#Movement not working

1 messages · Page 1 of 1 (latest)

ivory brook
#

I used the CharacterController2D movement script from 2D Movement in Unity (Tutorial) video and it worked when I followed the tutorial but when I use it in another project the values of horizontalmove changes in console but the character dosent move
please help Thank You

stark sandBOT
#

It's hard to answer a programming question without code

Resolving a bug is almost impossible when the question doesn't include any of the buggy code. In order to help fix the problem, answerers are going to have to see what the code is.
Source: https://idownvotedbecau.se/nocode

Please isolate the problematic code and send it as a codeblock. If you don't know how to send a codeblock, type []cb

ivory brook
#

[]cb

stark sandBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

ivory brook
#
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public CharacterController2D controller;

    public float runspeed = 30f;

    float horizontalmove = 0f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontalmove = Input.GetAxisRaw("Horizontal") * runspeed;
        Debug.Log(horizontalmove);
        
    }

    void FixedUpdate()
    {
        controller.Move(horizontalmove * Time.fixedDeltaTime, false, false);
    }
}
brisk zealot
#

@ivory brook the charactorcontroller needs a vector 3 to move

#

You’re putting in a float

#

That’s why it’s not working

ivory brook
#

@brisk zealot Where should I change the code

brisk zealot
#

@ivory brook change the horizontalMove to a vector3 and do something like horizontalMove.x

#

That should hopefully fix it

ivory brook
#

@brisk zealot But this worked in the previous project I did
following the unity 2d movement tutorial video

brisk zealot
ivory brook
#

Let’s give our player some moves!

● Check out Skillshare: https://skl.sh/brackeys7

● Character Controller: https://bit.ly/2MQAkmu
● Download the Project: https://bit.ly/2KPx7pX
● Get the Assets: https://bit.ly/2KOkwjt

♥ Support Brackeys on Patreon: http://patreon.com/brackeys/

·································································...

▶ Play video
brisk zealot
#

It might be outdated

#

Try turning it into a vector 3

#

Also check out the docs

#

@ivory brook how’d it go

ivory brook
#

@brisk zealot I made some changes but now its not letting me drag the CharacterController2D.cs into controller variable in PlayerMovement.cs

#
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public CharacterController2D controller;

    public float playerspeed = 2f;

    Vector3 horizontalmove;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontalmove = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
        Debug.Log(horizontalmove);
        controller.Move(horizontalmove * Time.deltaTime * playerspeed);
        
    }
#

@brisk zealot This is so confusing

#

I got it working with Vector 3 somehow but it logs in console but dosent move same problem:\

brisk zealot
#

So I realised you’re using a different controller from the one I linked

buoyant hearth
#

Depends on your frame rate, Time.deltaTime can be really small

#

Have you tried a higher speed?

ivory brook
ivory brook
#

@buoyant hearth Still not working

buoyant hearth
#

How do you know it’s not moving?
Is your camera following your character?

ivory brook
brisk zealot
ivory brook
brisk zealot
#

@ivory brook if nothing is working I say double check with the video one last time

#

And if you can’t figure it out

#

Then try maybe using a rigidbody

#

Fore movement

ivory brook
brisk zealot
#

Yeah

#

U can try with the 2D controller more

#

But there ain’t a lot of info about it

ivory brook