- Home /
Is mixing movement types a bad thing to do? (Force and Translate)
Hi,
Currently in my project I am using translation based movement to control my floating character which can move in all dimensions.
My character fires a projectile which is physics based and uses force to move it. When I shoot I find that my projectile does not take into account my relative speed, and it just looks / feels wrong. For example if I am moving left and fire, the projectile very quickly falls away to the right. I am guessing this is because it has no reference to any other physics velocity.
Am I going about my project structure the wrong way? If I am using any physics for one item should I be using physics for everything. Or is it OK to blend the two?
Thanks
Paul
as a general principle ... it's not "bad" -- it's just "advanced"
yes, your life would be easier if they were all physical. why not try changing it?
regarding your specific problem, as Owen explains you simply have to set the velocity to the sum of the gun's velocity and the desired bullet velocity.
Answer by Owen-Reynolds · Sep 23, 2012 at 03:16 PM
No, no, yes (but not on same object.)
No matter what, if you want to fire a bullet taking into account your velocity, you'll have to do it yourself. When you Instantiate a "physics object" (a rigid body) it has speed=0. Way too confusing for Unity to check whether the spawning script is on an RB and tweak speed if so.
If you want to give it your speed, add it: `bullet.rigidbody.velocity = transform.forward*20 + AAA;`. If you're a physics object, AAA is `rigidbody.velocity` (your speed.) If you have the standard third-person script, AAA is `moveDirection` (physics velocity is M/S, so make sure you don't use your per/frame speed by mistake.)
The thing that usually causes problems is when the same object uses code movement and physics-system movement. So if you want your bullet to jerk sideways mid-flight, set `rigidbody.velocity` to sideways (or temporarily turn off physics for it with `isKinematic` and begin using translate.)