- Home /
The question is answered, right answer was accepted
2D movement script is wrong?
Trying to get movement in a 2D space, using the code below. But No input is moving my player, a rigidbody and box collider are both on.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float speed = 50f;
public float jumpPower = 150f;
public bool grounded;
private Rigidbody2D rb2d;
void Start () {
rb2d = gameObject.GetComponent<Rigidbody2D>();
}
void Update () {
}
void FixedUpdate(){
float h = Input.GetAxis("Horizontal");
rb2d.AddForce((Vector2.right * speed) * h);
}
}
$$anonymous$$ake sure that you are using rigidbody2d and boxcollider2d ins$$anonymous$$d the 3d ones.
Answer by tanoshimi · Sep 22, 2016 at 07:05 PM
Because case sensitivity is important. The method is FixedUpdate
, not fixedUpdate.
And you've attached this to a gameobject in your scene? What value have you set for speed?
Yes, its attached to the player object, speed value of 50.
Follow this Question
Related Questions
2.5D Platformer - Jump Question 1 Answer
The main camera pans up when I press play.Please help. 0 Answers
Line Renderer. How to lock z axis for side scroller? 1 Answer
[2D] Check if player is on the ground 4 Answers
Trouble with Jumping Algorithm 1 Answer