#Movement not working
1 messages · Page 1 of 1 (latest)
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
[]cb
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.
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);
}
}
@ivory brook the charactorcontroller needs a vector 3 to move
You’re putting in a float
That’s why it’s not working
@brisk zealot Where should I change the code
@ivory brook change the horizontalMove to a vector3 and do something like horizontalMove.x
That should hopefully fix it
@brisk zealot But this worked in the previous project I did
following the unity 2d movement tutorial video
Can u link me the video? Might be outdated
@brisk zealot
https://www.youtube.com/watch?v=dwcT-Dch0bA&list=PLPV2KyIb3jR6TFcFuzI2bB7TMNIIBpKMQ&index=2
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/
·································································...
It might be outdated
Try turning it into a vector 3
Also check out the docs
@ivory brook how’d it go
@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:\
So I realised you’re using a different controller from the one I linked
Depends on your frame rate, Time.deltaTime can be really small
Have you tried a higher speed?
I used the one from brackyes video:
nope I try now
@buoyant hearth Still not working
How do you know it’s not moving?
Is your camera following your character?
No I checked with Scene screen next to game screen and it dosent move
Is the character position changing?
No thats the problem
@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
but then I should change the animations manually right to like flip and jump?
I think so
Yeah
U can try with the 2D controller more
But there ain’t a lot of info about it
It worked with rigidbody thank you:)