- Home /
Keeping gun on straight axis
Does unity have object constraints? I'm working on a top down shooter, with bullets spawning from a spawn point at the gun muzzle, and some animations are skewing the bullets all over the place..
Is there a way to lock the gun to an axis, to ensure straight bullets (preventing bullets from sloping up or down)
I'm avoiding using a rigidbody
Answer by ExpiredIndexCard · Mar 29, 2013 at 01:48 AM
Add a rigidbody and uncheck "Gravity". If you do not want gravity then do that. Maybe set the object to always be at Vector3.Forward so it is always facing that direction. Please upload your script so I can tell you what you need to do. It helps to see what's "Under The Hood" sometimes ;)
I was thinking of forward as well, was going to set it as the player's forward, but would this have to be updated every frame in Update or does Unity provide a static for this?
Answer by $$anonymous$$ · Mar 28, 2013 at 10:23 PM
if your gun has a rigidbody attached to it, you can prevent it from rotating by checking the boxes in Constrains ----> freeze position. if your gun doesn't has a rigidbody, use
transform.position.x = 0; //or whatever axis/position you want
I'm avoiding rigidbody because I don't want it to have it's own gravity, and I don't know how to approach adjusting the transform position/rotation of the gun as this is changing every second..
Your answer
Follow this Question
Related Questions
Can't "Add Property" to animation! 1 Answer
Can I make animations snap to a frame? 1 Answer
Combat Animating 0 Answers
Physics based combat reactions merged with animations? 0 Answers
IK for Precise Parrying Animations - Sword Combat System 1 Answer