- Home /
Question by
bekiramina1994 · Sep 13, 2017 at 01:25 AM ·
unity 5rigidbody2dvelocityspeedaxis
Issue regarding Rigidbody2D
i have been running this program for move the sprite but nothing is changed , can you help me ?, please
public class PlayerScript : MonoBehaviour { ///
/// 1 - The speed of the ship /// public Vector2 speed = new Vector2(50, 50); // 2 - Store the movement and the component
private Vector2 movement;
private Rigidbody2D rigidbodyComponent;
void Update()
{
// 3 - Retrieve axis information
float inputX = Input.GetAxis("Horizontal");
float inputY = Input.GetAxis("Vertical");
// 4 - Movement per direction
movement = new Vector2(
speed.x * inputX,
speed.y * inputY);
}
void FixedUpdate()
{
// 5 - Get the component and store the reference
if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>();
// 6 - Move the game object
rigidbodyComponent.velocity = movement;
}
Comment