- Home /
Question by
Marsealdelo · Aug 08, 2013 at 01:29 AM ·
2dguimovement
Help setting maxAceleration
Please help my script,,i want to make my default maxAcceleration = 5 when play, and if no input horizontal, maxacceleration going to 5 again, can you help me please ? and if i press left key, maxAcceleration not going to -10 but 0 ... please :(
//GERAK NORMAL
var Acceleration : float = 30;
var maxAcceleration : float = 5;
@HideInInspector
var horizontalMovement : Vector2;
function Update ()
{
//GERAK NORMAL
horizontalMovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
if(horizontalMovement.magnitude > maxAcceleration)
{
horizontalMovement = horizontalMovement.normalized;
horizontalMovement *= maxAcceleration;
}
rigidbody.velocity.x = horizontalMovement.x;
rigidbody.velocity.z = horizontalMovement.y;
rigidbody.AddRelativeForce(Acceleration,0,0);
}
function OnGUI ()
{
maxAcceleration = GUI.HorizontalSlider (Rect (100, 150, 100, 10), maxAcceleration, 0, 10);
maxAcceleration = Input.GetAxis("Horizontal") * 10;
}
Comment
You can simply change your code a little bit:
maxAcceleration = 5 + Input.GetAxis("Horizontal")*5;
I'd like to re$$anonymous$$d people to put there answers as an answer or people cannot mark it as the answer.