- Home /
Trajectory problem with addforce coordinates
The basic tenant is to 'Fire and forget'... No matter where I turn the projectile should remain on target.
I fire a projectile in a GameObject. It travels away from the viewer towards a target in the distance. When I spin the GameObject on the x or y axis, the projectile's postion spins with the environment. In other words the projectile is heading towards the target. When I stop the GameObject from spinning the original trajectory takes over and the projectile is once again going away from the viewer when it should maintain it's course towards the original target. So the position of the projectile follows the GameObject's positioning but the trajectory does not maintain course. I could call this a feature, but I need a realistic play at first. It is always away from the viewer or if it hits something and bounces off that is the new trajectory even though the world is rotating. I believe I am mixing component/local values with world values although I am not sure what to check. Has anybody else seen this?
TIA
The GameObject is a GameObject not a rigidbody. The projectile is
var Pulsarshoot = Instantiate(Pulsarshoot, GameObject.Find("SpawnPoint").transform.position,Quaternion.identity); Pulsarshoot.rigidbody.AddForce(transform.forward * 50000); Pulsarshoot.transform.parent = GameObject.Find("cueb").transform;
as a rigidbody. Spawnpoint is a rigidbody.
I believe this is the culprit:
Pulsarshoot.rigidbody.AddForce(transform.forward * 50000);The force is coming from the rigidbody spawnpoint, correct?
First, is this a GameObject or a Rigidbody? It seems like you are describing rigidbody movement.
Actual problem:
You create a GameObject with rotation (0,0,0) at (0,0,0). Up (local up) is (0, 1, 0)
You rotate it 90 degrees on the X axis. Local Up is now (0, 0, -1). See the problem?
If you ONLY move using ABSOLUTE values, then this should not be a problem.
Answer by aldonaletto · Jul 30, 2011 at 04:16 AM
It seems you're using some vector from the original GameObject to apply force to the projectile after launched - if the projectile was launched with only an initial velocity or force, its trajectoy would be independent of the launcher.
But this is only speculation, because you've not posted your code. Post the code and we can check what's wrong.
EDITED: Based on your code, I suppose the real problem is the parenting to the "cueb" object (whatever it is). Since the projectile is a child of this object, any rotation or movement the object does will affect the projectile as well.
The initial force is ok: it should really follow the fire and forget rule, since it's applied only once - you would have problem only if the force was being applied during the trajectory.
If you need to child the projectile to something for any reason, make sure the parent object will not rotate or move while the projectile is alive. The rule is: child movements do not affect the parent, but parent movement DOES affect the child.
In this case the child maintains its position with the parent but the force applied to the child for a given trajectory does not rotate with the parent. I fire, the projectile goes away from the instantiation point. When I rotate the parent 180 degrees the projectile is co$$anonymous$$g at the instantiation point. Reparenting does not help. I don't know to make this any clearer. I have spent days trying to get this to work. Is it because the main camera is not in the parent object but outside watching everything rotate?
Your answer
Follow this Question
Related Questions
Why is force only being added in the same direction? 1 Answer
AddForce to object 3 Answers
AddForce to the Left? 3 Answers
add force to object that has 2 different rigid bodies 0 Answers
How do I apply a force to the other object in a collision? 1 Answer