- Home /
Why Use InputManager over the easy transform.Translate?
{ transform.Translate(new Vector2(speed * Time.deltaTime, 0)); }
{ float controlThrow = CrossPlatformInputManager.GetAxis("Horizontal"); Vector2 playerVelocity = new Vector2(controlThrow * speed, myRigidBody.velocity.y); myRigidBody.velocity = playerVelocity; } What is the basic difference between these two as I think both do the same job?
Answer by oStaiko · Sep 02, 2020 at 06:36 PM
There's a very big difference between the two. In fact there's almost nothing similar between them, this is like comparing apples to sea urchins. InputManager is a system that records key presses from your keyboard/controller, whereas Translate moves a GameObject. What you're probably thinking of is "Whats the difference between transform.Translate() and Rigidbody2D.velocity"
In your first example (using translate) you can only move in one direction, and at a constant speed. It doesn't use physics but instead updates its position manually every frame, while checking for collisions. This code would be placed in Update().
In the second example, the player controls the initial x-axis velocity. This looks as if the player is throwing an object and forgetting about it, vs how the previous one IS the object. This would be placed in an initialization method, such as Throw().
The main difference between these two methods is if you want to use physics or not. The answer to that question really depends on the kind of game you're making.
Your answer
![](https://koobas.hobune.stream/wayback/20220613011024im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Simple Scripting Question 2 Answers
Vector doesn't get calculated 1 Answer
C# 2D Translate Forward Based on Rotation 1 Answer
Translation in 2D with a normalised vector. 2 Answers
Simple C# Vector2D Moving Question 1 Answer