- Home /
Add Force without Rotation
I've been playing around with the add force physics in Unity for a few hours now but have been stuck at this point for a long time -
I'm trying to add a force to an object, similar to thrust, that pushes the object from behind. I started by adding a force to a sphere, then using the smooth follow script to make the object follow it, this didn't work. It seems that adding force to a cube object comes out with some weird results for me.
How is it possible to make a object move forward, using add force, without it going 'Weird' and shaking all over the place?
I'm using a simple rigid body on the object, then using the line :
rigidbody.AddForce(transform.forward * 20);
Yet my results are really quite weird. It seems to be that the spheres are fine with this, however cubes act it a strange way.
I decided to create an empty game object, added the script to it, then parented it with the other object making sure the empty game object was behind when parented, this still gave me some weird results.
Where am I going wrong here? What is it that I'm messing up on?
Thanks in advance,
~ Alex
Answer by robertmathew · Mar 14, 2011 at 01:29 PM
unckeck the gravity box it will work fine because of gravity you have checked it is going like this
I still want to use gravity, I just want to exert the power from the empty game object, but move the object it's parented to.
rigidbody.useGravity = true
or false where you want to enable or disable the gravity
I understand that part - But at the moment what I know and have been told, I'm not getting any results, just a box sitting still..
if you use gravity the object will work according to the gravity only as you put gravity on first it will go down because of gravity then move forward to add force so change the code according to your need if you off the gravity it will move forward correctly
Why not freeze the rotation of the rigidbody? Is that what you are looking for?
Answer by Bunny83 · Mar 14, 2011 at 08:02 PM
That sounds like a friction problem. If you try to push your cubboard across your carpet I'm quite sure it will tilt because it get stuck on the ground. You have two things you can try:
- Setup your PhysicMaterial of your box and the ground and set some low friction values to "grease" the movement.
- Use Rigidbody.AddForceAtPosition to lower the attack point where you apply your force.
The physics are designed to simulate the real world, so you need real world solutions ;)
Your answer
Follow this Question
Related Questions
add force to object that has 2 different rigid bodies 0 Answers
Get result (force & torque) of AddForceAtPosition? 2 Answers
Why is force only being added in the same direction? 1 Answer
Predicting land position with drag applied 0 Answers
What is the best way to apply force, then come to a smooth stop on control release? 1 Answer