- Home /
fire tank in any direction
Hi,
I have a tank gun attached to the FPS as a long cube pointing in Z direction.
I want to move the tank gun from the end point in a X,Y direction and have a ray cast from the direction it is pointed.
q1) to move the tank gun from the end point what am I doing as I have tried moving position but it moves from middle of the object.
q2)To cast a ray from the direction it is pointing I tried this moves in X direction only. Debug.DrawRay(transform.position, fwd * 100, Color.red);
Answer by syclamoth · Jun 11, 2012 at 02:11 AM
q1: Make an empty transform for the 'pivot point', and make the rest of the gun a child of that pivot (then rotate the pivot, not the gun)
q2: Well, if you use Vector3.forward, it will only ever go in one direction! Try this:
Ray(transform.position, transform.forward);
q1) Could you explain this further please as I am a little new to unity3d. I create an empty game object and have the actual gun a child to this game object, then rotate this game object.
Yes, that's what I mean. What part of it is giving you trouble?
Your answer
Follow this Question
Related Questions
Animating Tank Treads 0 Answers
firing a shell from a tank turret 1 Answer
Multiplayer projectiles collision 0 Answers
player on trigger enter dont work? 1 Answer
Tank Setup Problem 1 Answer