- Home /
Foces only change during collision
I am trying to control a cube with the keyboard inputs. I want to change the acceleration of the cube while it is in the air, but the applied forces will only update during a collision or if I set the drag to a large value. I have included my code below.
using UnityEngine;
using System.Collections;
public class CubeMove : MonoBehaviour {
private Vector3 input;
private float maxSpeed=5f;
private float accelSpeed=500f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
input=new Vector3(Input.GetAxisRaw("Horizontal"),0,
Input.GetAxisRaw ("Vertical"));
if(rigidbody.velocity.magnitude<maxSpeed){
rigidbody.AddForce(input*accelSpeed,
ForceMode.Acceleration);
print(rigidbody.velocity);
}
}
}
Note that you should be calling the 'rigidbody.AddForce() inside FixedUpdate(), though I don't think that is your problem. Your 'accelSpeed' is really high for a force that is applied every frame.
Answer by ewall198 · May 10, 2014 at 01:40 AM
I figured it out, The magnitude was higher than maxspeed.
I am so silly
Your answer
Follow this Question
Related Questions
move player to its rotating direction? 2 Answers
Update speed and physics makes my rigidbody jiggle 2 Answers
AddForce/ForceMode.Impulse 1 Answer
Erratic Physics behaviour while testing in 2 computers 0 Answers
adding force 1 Answer