- Home /
Translation issue
Hello i'm a fresh user of Unity3D and i'm trying to make some kind of 3D platformer where a cube needs to hit another cube to win the level with walls between the two.
The problem is that when my cube moves when pressing the left arrow for example he moves on the X, Y and Z axis but i only want him to move on the x.
it seems like he moves on the x but he hits the floor and that makes him go a bit up and down (0.2) but he moves a lot on the Z axis unfortunately.
So my question is how can I stop it from hitting the floor and doing that ? I just want him to glide smoothly.
code of the translation :
// Player Movement
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * Time.deltaTime * speed);
}
Thanks
Answer by grahnzz · Apr 19, 2014 at 03:22 AM
It sounds like you have a rigidbody component attached to your player, if thats the case then i would recommend using rigidbody methods to apply translations to your player. ex:
rigidbody.velocity = Vector3.right * Input.GetAxis ("Horizontal") * Time.deltaTime * speed;
or
rigidbody.AddForce(Vector3.right * Input.GetAxis ("Horizontal") * Time.deltaTime * speed);
to prevent movement on certain axes checkout https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-constraints.html rigidbody.constraints is accessible the inspector as checkboxes i belive
@$$anonymous$$annoFR please click the 'Accept this Answer' to earn a little karm for yourself and @grahnzz
Your answer
Follow this Question
Related Questions
Issue with DontDestroyOnLoad 0 Answers
ScreentoWorldPoint position android issue 1 Answer
Issue with build display settings 0 Answers
A Cube That I Pick Up Acts Kinematic, Although it Isn't. 2 Answers
WWW.bytesDownloaded freeze 0 Answers