Question by
tums93tx · Apr 05, 2019 at 05:32 AM ·
addforcerigidbody.addforce
Rigidbody.addforce not working,i cannot get my AddForce function to work. it reads the input but will not make the player move. the player has a rgidbody on components as well.
My player character has a rigidbody but the addforce function is not making the character move. ive tried putting it in the FixedUpdate and the normal Update.
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
private float maxSpeed = 6;
private Vector3 input;
void Start()
{
}
void FixedUpdate()
{
if(GetComponent<Rigidbody>().velocity.magnitude < maxSpeed)
input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
GetComponent<Rigidbody>().AddRelativeForce(input * moveSpeed);
}
}
,
Comment
i have tested abd the code works, make sure moveSpeed isnt zero in the inspector
Your answer
Follow this Question
Related Questions
Predicting max jump height of a force impulse 1 Answer
Confused about addForce behavior on 3D objects w/ sub-objects in 2D movement 0 Answers
How to AddForce up to a certain height and then stop? 0 Answers
Need help for applying force to rigidbody with .AddForce 0 Answers
AddForce 2D it's not working 0 Answers