Posts by Yin

    when you drag the acid prefab into the scene view, is it at the 0, 0, 0 position? If it is, move it over to where the spider is and the hit "apply" on the prefab to change it's initial position. OR, when instantiating the acid, give it the spider's transform.position.

    Ok, one thing at a time...

    the problem with line 37 is that you're changing the touchPadInput by Head.transform.forward.

    touchPadInput += Head.transform.forward;

    is the same as

    touchPadInput = touchPadInput + Head.transform.forward;

    the result is that your touchPadInput changes. That should only be read from the touchpad itself.

    For the playerAgentMove input, the line I suggested was this:

    playerAgent.Move(touchPadInput.y *Head.transform.forward*movementSpeed);

    touchPadInput.y is a scalar.

    Head.transform.forward is a vector3.

    movementSpeed is a scalar.

    When you multiply them together, you have a vector3.

    as for the rotation with quaternions, just use quaternions.euler to transform the desired rotation angle to quaternions.

    shouldn't it be changing Head.transform.position in line 37 and not touchPadInput?

    Head.transform.forward is just a unit vector in the direction you're facing.

    You can also make it so that you do the forward/backward movement separately from the turn.

    playerAgent.Move(touchPadInput.y *Head.transform.forward*movementSpeed);

    and then the rotation:

    Head.transform.rotation += touchPadInput.x;

    Alternatively, you can use slerp or something to make that turn smoother.

    That's because you're just detecting Input.GetMouseButtonDown. That will trigger no matter where you click.

    You need to use Input.mousePosition to actually see which object was clicked. You can use that in combination with a Raycast to identify the "clicked" object.

    the out of range is because of line 7. You're using the same index i for both lists. I'm assuming the required items list is shorter than the inventory items list.

    Also, line 9 is still weird. It should be something like Inventory.instance.items.Remove(Inventory.instance.items[i]).

    or Inventory.instance.items.RemoveAt(i).

    So just to backup here, why are you using a loop to search at all? If you're using a List, you can just do a single loop:

    1. for( int i = 0; i< itemToCraft.requiredItems.Count; i++)
    2. {
    3.     if(Inventory.instance.items.Contains(itemToCraft.requiredItems[i]))
    4.     {
    5.         Inventory.instance.items.Remove(itemToCraft.requiredItems[i]);
    6.     }
    7. }

    I'm assuming my lists are not the objects but their names only, so lists of Strings. At this point, I'd recommend you use a dictionary and not a list as the key-value pairs are much easier to access.

    Where you have line 20: Inventory.instance.Add(itemToCraft.finalProduct);

    I think it should be on the outside of the foreach loop.
    Also, your list is Inventory.instance.items, right? line17 should be Inventory.instance.items.Remove(item).

    Not sure what it's currently removing, maybe the whole list? That may be why it stops after finding one thing.

    So it also seems like you're doing this kind of backwards...
    your code goes through your player's inventory to see if each of the inventory items match the required items.

    It seems like you should go through the required items to see if they exist in the inventory.
    Also, you're adding the finalProduct without checking if all the requiredItems have been accounted for.

    Are there parts of the code that you are omitting here? If so, that's fine, otherwise, you may need to do that check.

    There's also the possibility of using the Animator state machine to control an action/reaction state machine. You can just save the same animation as different .anim files to create the different states and then use the animation triggers and transitions to control the resultant actions. That gives those of us who are more visually inclined a better grasp of how the different states interact and transition.