Jump to content

Sprinting Animation for forge mob? (Geckolib)


irludure

Recommended Posts

So I made an elephant, but I'd like to make it so that when it is going towards a target, it uses a run animation instead of a walk animation.

Here is my current code:
 

    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
        System.out.println("Attempting predicate...");
        if (event.isMoving()) {
            System.out.println("IsMoving = true!");
            if (getTarget() != null) {
                System.out.println("Target != null!");
                event.getController().setAnimation(new AnimationBuilder().addAnimation("run", true));
            } else {
                System.out.println("Target is null...");
                event.getController().setAnimation(new AnimationBuilder().addAnimation("walk", true));
            }
            return PlayState.CONTINUE;
        }

        event.getController().setAnimation(new AnimationBuilder().addAnimation("idle", true));
        return PlayState.CONTINUE;
    }

It uses the getTarget() method from the Mob class. However, it doesn't ever use the run animation, even if it is going after a mob. It still prints "Target is null...". And, the getTarget() method returns null everytime. Does anyone know how to fix this?

Link to comment
Share on other sites

 

4 hours ago, ChampionAsh5357 said:

The target is either set via the mob or, typically, by a `TargetGoal` via the `targetSelector`. See `IronGolem` for an example.

I already have a HurtByTargetGoal() setup and a MeleeAttackGoal(). They work correctly, I just can't seem to find out how to check if it is targeting something currently.

Link to comment
Share on other sites

On 5/27/2023 at 2:44 PM, irludure said:

I already have a HurtByTargetGoal() setup and a MeleeAttackGoal(). They work correctly, I just can't seem to find out how to check if it is targeting something currently.

Just check whether `#getTarget` is not null then. You already seem to be doing that, so most likely is that the data is not synced to the client. Maybe you should add a SynchedDataAccessor and set the value to true or false depending on `#setTarget`.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.