Forum rules - please read before posting.

Jumping and "Attacking"

Hi. Sorry to put up two in one day. I know how to set up AC's jump, but the character doesn't land properly. They walk in midair until they hit the ground and I don't know how to fix this 

Or would it be better to set up a falling animation.

Lastly, I know AC isn't built for violent games, but I was wondering if a setup similar to a platformer was possible, where an interaction renders a previously active NPC null 

If not I'll use playmaker to fill in the gaps. Thanks!

Comments

  • Is it 3D? Sounds like a rigidbody issue. Does your player have one? if it does have one, it might be kinematic which would not apply any physics to it (or it might not be set to use gravity). Either of these two cases would make it impossible for the player or object to fall to the ground.

    When you say platformer, you mean like mario bros? you could easily put an AC trigger around an "enemy", and have the trigger run an actionlist when "hit" by the player. The actionlist could play and animation and then destroy said enemy, but instancing/destruction might be an issue because AC uses unique constant IDs to instance or destroy an object (when destroying it may just pick the first enemy it finds with the right constant ID). To solve it you could have a whole range of enemies with different constant Ids. but some custom scripting would probably be better otherwise.
  • edited December 2016
    Destroying an object in code is rather simple:

    using UnityEngine;
    using System.collections;
    using AC;

    //next part goes inside the class - enemy or whatever
    public int LifePoints = 3;

    public ActionListAsset ToDoWhenHit; //play sound, update score, etc
    public ActionListAsset ToDoWhenDying; //play sound, update score, etc

    public string HitAnimState = ""; // name of animation
    public string DieAnimState = "";

    public float DelayBeforeDestruction = 0f; // set it slightly longer than die animation

    private Animator _animator;//enemy needs animator
    private bool _dying;

    void Awake()
    {
       _animator = GetComponent<Animator>();
    }

    void OnTriggerEnter(Collider other) //enemy needs trigger collider
    {
        if(other.tag =="Player")
        {
           if(LifePoints<=0)
           {
               if(!_dying)
                   StartCoroutine(Destruction());
           }
           else
           {
               _animator.Play(HitAnimState);
               LifePoints -=1;
               AdvGame.RunActionListAsset(ToDoWhenHit);
           }
           
        }
    }

    IEnumerator Destruction()
    {
       _dying = true;
       _animator.Play(DieAnimState);
       AdvGame.RunActionListAsset(ToDoWhenDying);
       yield return new WaitForSeconds(DelayBeforeDestruction);
       Destroy(gameObject);
    }
  • Is the jumping/floating issue to do with animation or motion?  We'll need more detail in order to help on that one, but bear in mind the defined "Jump bool" parameter in your Mecanim Inspector will remain ticked until the player becomes grounded again.  You should design your Mecanim FSM to prevent walking when this is the case.
  • edited December 2016
    The jumping problem is the animation. Here's a recording


    If I'm already walking, it just sort of walks into the air
    If I'm not already walking it leaps and then returns to the idle position midair while landing
    if I'm not already walking and then move while midair it finishes the animation and holds it until I stop moving
    There's playmaker states, but those just help move the camera 
    I'm pretty certain I must have missed something while setting this up.
    Thanks for the responses.
  • Took care of all of the jumping related problems, the only issue left is that I'm not sure how to go about triggering a fall animation while on the AC player controller
  • That should be down to the way your Animator is set up.  Once the jump animation has completed, you'll want to wire up your Mecanim controller so that the falling animation then kicks in.  If you then want to play a "land" animation, you'll want to create a new transition from "falling" to "land" that kicks in when your "Is Jumping" bool is set to False.
  • That looks just about perfect, thanks! The only problem is if I don't let of the space bar during a jump the bool doesn't turn off and wont turn off until I let go.
    This doesn't happen from stationary jumps
  • So this problem only occurs if you're walking/running first?  Do you have a separate jump/fall animation chain for that, or do you use the same one when idle as well?
  • edited January 2017
    It happens if I move any direction while falling and I'm still holding the directional keys after having landed. I currently have just an idle to jump and then fall to idle. But I made all the anims myself so if its a run/walk to jump anim I need I can fix this.


  • I was asking that because if you did have other anims, it would make the problem more complex - that you don't keeps things more simple for now.

    I can't recreate this issue myself, however.  It could be that you're transitioning Idle -> Jump, rather than a "Locomotion" Blend tree to your Jump/Fall anims.

    The best way to debug this would be to keep your live Animator window open while testing the game.  When the issue occurs, you'll be able to see the cause - i.e. the "Jump bool" parameter not being turned off correctly, or the animation transitions not being correctly set up.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.