Question by
MrLiber777 · Jan 06, 2016 at 07:27 PM ·
charactercontroller
C# question
Hi you know i can't make character move, because c# doesn't accet word "velocity". Help me solve this problem please
public class MarioController : MonoBehaviour {
public float maxSpeed=10f;
bool facingRight=true;
void Start ()
{}
void FixedUpdate ()
{
float move = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Flip ()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Comment
Answer by jmonasterio · Jan 06, 2016 at 08:39 PM
Use rigidbody2d.AddForce(...) method at line 11 to change velocity, instead of trying to change the velocity directly, like you're doing.
The problem is that Unity.Engine component does not contain defintion for velocity
Your answer
Follow this Question
Related Questions
Boat Controller Help 0 Answers
My Character won't jump 0 Answers
How to capture coordinates of avatar and save it some or pass it? 0 Answers
I need help with movement please help me 0 Answers
Why won't my character jump? [JS] 0 Answers