- Home /
How to make a basic 2d movement script for a 3d game
hello,i was making a 3d game but the character in the game is a 2d sprite and i want the sprite to have a 2d left to right walk and a jump movement script on it and the script that i put on my sprite dosent work to well because it has rigidbody and when an object has rigidbody body is needs a collider or else its gonna fall through other object so when i put a collider on my sprite it dosent go on my sprite to well and the sprite cant walk right how can i make it to where i don't need rigidbody for my sprite to walk and how can i add a jump movement to my script.
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {
public float speed;
void Awake () {
}
void FixedUpdate () {
if (Input.GetKey("a")) {
GetComponent<Rigidbody>().AddForce (-Vector3.right * speed * Time.deltaTime);
}
if (Input.GetKey("d")) {
GetComponent<Rigidbody>().AddForce (Vector3.right * speed * Time.deltaTime);
}
}
}
Answer by kevinspawner · Aug 17, 2015 at 07:59 AM
You need to replace the Rigidbody with Rigidbody 2D in your script.
Replace the Rigid body component in your inspector with Rigidbody2D.
thanks that solve one problem now how can i get my sprite to jump
Link: http://answers.unity3d.com/questions/798998/i-only-want-my-character-to-jump-when-touching-the.html
You can mark the answer as completed if it solves your problem.
Your answer
Follow this Question
Related Questions
Sprite animation 2 Answers
Saving Rotation of Sprite 1 Answer
Problem with mooving sprites 1 Answer