- Home /
How do I make my character jump over a cube with rigid body moving towards it
pls can anyone help! I'm new to unity and I'm trying to make my character jump over a cube moving towards him but the rigidbody attached to the cube makes it impossible to jump over. Both the character and cube have rigid bodies attached to them. Also when the cube is in motion (moving towards the character) it allows the character pass through it instead of repeling the player back on collision. Pls any advice wud b really appreciated. Thanks in advance. This is the script I used to move the cube towards him.
#pragma strict
var speed:float = 17.0f; // move speed
function Start () {
}
function Update () {
transform.position = Vector3.MoveTowards(transform.position, Vector3(-0.0001,3.67707,7.64789), speed*Time.deltaTime);
}
Answer by HappyMoo · Jan 04, 2014 at 02:46 AM
If you move rigidBodies by changing their positions, the physics system doesn't work.
move the rigidBodies in FixedUpdate by applying forces to them or setting the velocity.
function FixedUpdate()
{
rigidbody.velocity = Vector3.forward*speed;
}
I'd like to add on to this answer, have a look at rigidbody.$$anonymous$$ovePosition.
Thanks so much for the replies...I really appreciate it. But the cube still passes through the character ins$$anonymous$$d of repeling him backwards. Pls any advice on how to solve dat? Thanks in advance once again
Did you also add Colliders? This gives a good overview over Unity's Physics: http://unity3d.com/learn/tutorials/modules/beginner/physics
@Happy$$anonymous$$oo yes I did but I'm not too sure of the type of collider I'm supposed to add to my game character, he already has a rigidbody, character controller and an animator, but my cube has a box collider and a rigidbody...pls which type of collider can I add to my character? Thanks in advance
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How can I create a "round arc" physics based jump? 2 Answers
Translation of an object 2 Answers
Make jump high as long as you press? 0 Answers
hit.normal cube 0 Answers