Forum rules - please read before posting.

Player doesn't move after the build (in the Unity Editor it moves)

Hi and happy New Year!

In the Editor, player moves:

subsequencegame.com/img_blogs/ele_working.mp4

But after the build, it doesn't (WIN10/64bit build):

subsequencegame.com/img_blogs/ele_notworking.mp4

Animation is working, but "transform.position" isn't.

On my Player prefab I have attached this innocent script:

`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class climb : MonoBehaviour
{

public Animator anim;

void Start()
{
    anim = GetComponent<Animator>();
}

void Update()
{
    if (Input.GetButton("splhN"))
    {
        anim.Play("climb");
        transform.position += new Vector3(0, 0.03f, 0);

    }
    else if (Input.GetButton("splhD"))
    {
        anim.Play("climbD");
        transform.position += new Vector3(0, -0.03f, 0);

    }
    else {
        anim.Play("idle");
    }

}

}
`

And this is the ActionList when player jumps on the ladder:

In the Editor everything works fine, but after the build Player doesn't move (only animation is working).

Please do you know what I'm doing wrong?

Thanks!
Jakub

Comments

  • For a custom script to control the Player's position, you'll need to set their Motion control field to Manual.

    To have this be set by the script, you'd need explicit TurnOn/TurnOff functions, i.e.:

    using UnityEngine;
    using AC;
    
    public class climb : MonoBehaviour
    {
    
        Animator anim;
        Player player;
    
        void Start()
        {
            anim = GetComponent<Animator>();
            player = GetComponent<Player> ();
        }
    
        public void TurnOn ()
        {
            player.motionControl = AC.MotionControl.Manual;
        }
    
        public void TurnOff ()
        {
            player.motionControl = AC.MotionControl.Manual;
        }
    
        void Update()
        {
            if (player.motionControl == MotionControl.Automatic)
                return;
    
            if (Input.GetButton("splhN"))
            {
                anim.Play("climb");
                transform.position += new Vector3(0, 0.03f, 0);
    
            }
            else if (Input.GetButton("splhD"))
            {
                anim.Play("climbD");
                transform.position += new Vector3(0, -0.03f, 0);
    
            }
            else {
                anim.Play("idle");
            }
    
        }
    
    }
    

    The TurnOn/TurnOff functions can be triggered using the Object: Send message Action.

  • Hi, @ChrisIceBox and thanks for the answer!

    Unfortulately, it still doesn't work:-(

    I tried this:

    using UnityEngine;
    using AC;
    
    public class climb : MonoBehaviour
    {
    
    Animator anim;
    Player player;
    
        void Start()
        {
            anim = GetComponent<Animator>();
            player = GetComponent<Player>();
            player.motionControl = AC.MotionControl.Manual;
        }
    
        void Update()
        {
    
            if (Input.GetButton("splhN"))
            {
                anim.Play("climb");
                transform.position += new Vector3(0, 0.03f, 0);
    
            }
            else if (Input.GetButton("splhD"))
            {
                anim.Play("climbD");
                transform.position += new Vector3(0, -0.03f, 0);
    
            }
            else {
                anim.Play("idle");
            }
    
        }
    }
    

    But when is motion changed to Manual, it fires Player to somewhere:

    subsequencegame.com/img_blogs/ele_jump.mp4

    I think I'm still doing something wrong...

    Have you any idea please?

    Thanks,
    Jakub

  • edited January 19

    My goal is to have player attached on the ladder, and by pressing W and S move the player up and down and play custom climb animation.

    That is all I want:-)

    So maybe there is another approach, I googled it here on the forum but i didn't find anything.

  • Once the motion control is set to Manual, AC is no longer a factor in the character's position.

    Make sure you have gravity disabled, and you'll need to multiply the movement vector by Time.deltaTime, i.e.:

    transform.position += new Vector3(0, -0.03f * Time.deltaTime, 0);
    

    The other approach would be to use root motion, so that the change in height is automatically synced to the animation being played.

  • Root motion was the trick!
    Thank you very much!
    Have a nice day, Chris!
    Jakub

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.