- Home /
AddForce to the Left?
For some reason my GameObject keeps getting knocked to the right instead of to the front and thats why I wanted to know if I could add force to the left? I am using this line:
Hit.rigidbody.AddForceAtPosition(transform.forward * Force , Hit.point);
[https://docs.unity3d.com/ScriptReference/Rigidbody.AddExplosionForce.html][1]
look at this [1]: https://docs.unity3d.com/ScriptReference/Rigidbody.AddExplosionForce.html
Answer by Borzi · Sep 04, 2013 at 05:01 PM
Okay so this is what I did, I it seems like this just works out perfectly and is a simple solution :)
if(Hit.collider.rigidbody)
{
//Make the object fly away by adding force to it
Hit.rigidbody.AddForceAtPosition(Force * FirePoint.transform.forward, Hit.transform.position);
//Check if it hit and Object
Debug.Log("Added Force to Rigid Body");
}
Just wanted to post this in case anyone else had a similar problem.
Answer by meat5000 · Sep 04, 2013 at 02:30 AM
AddForceAtPosition adds rotation, maybe that's why it seems to go the wrong way. Either that or your models axes are misaligned.
Try AddRelativeForce
rigidbody.AddRelativeForce (-1, 0, 0); // 1 Unit left in local axes
Well its a sphere, so the objects rotation could hardly be misaligned or what do you mean? And how would you implement AddRelativeForce. As a separate line I suppose?
Just because it's a sphere it doesn't mean it doesn't have axes or a relative direction. AddRelativeForce is implemented in the same way, just the Vector3 is in local space...that's coordinates relative to the object not relative to the world.
Your answer
Follow this Question
Related Questions
GameObject facing hit.point doesn't always work 1 Answer
How to find an object directly above another w/out Raycast? 1 Answer
How to get Vector3 of force that WILL BE applied to Rigidbody with AddForce()? 0 Answers
Moving gameobject along terrain based on player movement using raycast 1 Answer
Adding rotation to Physics.AddForce(); ... Getting weird error? 0 Answers