This question was
closed Mar 05, 2016 at 01:13 PM by
MasiaT_max for the following reason:
Problem is not reproducible or outdated
Question by
MasiaT_max · Feb 22, 2016 at 02:58 PM ·
c#movementspeed
Something is wrong with my max. speed code
using UnityEngine; using System.Collections;
public class Movement : MonoBehaviour {
public Rigidbody rigidbody;
public float velocity = 9f;
private float topSpeed = 12f;
private float acceleration = 10f;
void Start(){
rigidbody = GetComponent<Rigidbody> ();
}
void FixedUpdate(){
float movehoriz = Input.GetAxis ("Horizontal");
float movevert = Input.GetAxis ("Verical");
Vector3 direction = new Vector3 (movehoriz,movevert , 0.0f);
rigidbody.AddForce (direction * acceleration * Time.deltaTime);
if (rigidbody.velocity.magnitude > topSpeed) {
rigidbody.velocity = rigidbody.velocity.normalized * topSpeed;
}
}
}
Comment
Are you expecting us to guess what's wrong here? You might want to describe the actual problem...
I just want to make a simple code for movement with the maximum speed.