Somebody knows how my turret can rotate one (parent)part in X, another part (child) in Y to target at enemy when the enemy is near?
Thanks for the help
Somebody knows how my turret can rotate one (parent)part in X, another part (child) in Y to target at enemy when the enemy is near?
Thanks for the help
Am I right in thinking you have a base that rotates left-right and something like a gun mounted on it (as a child object) that points up-down?
I’ve attached a script that does something along these lines. Basically, you need to get a heading vector from turret to target by subtracting the turret position from the target position. If you set the Y component of this vector to zero, you get a vector in the XZ plane. Then, set the rotation of the base to look in this XZ direction using Quaternion.LookRotation. There will be no up-down motion.
Then, in the LateUpdate function, get the heading again (ie, not the XZ heading) and point the gun in that direction. Since all the changes in Update have occurred before LateUpdate starts, the base and the child gun will already be pointing in the right XZ direction, so you can just point the gun directly at the target. There are ways to calculate the up-down motion together in the Update function if necessary, but this is somewhat easier.
221866–8043–$gunturret_148.js (441 Bytes)
Cool, but question… what does transform.Find do?
Unity documentation:
I can’t think of a way to put it any clearer than the documentation already does.
thanks a lot, it’s so simple…
A question here… ¿Works with a mesh making the ground?
I’m not clear as to why using a mesh for the ground would make any difference. Can you explain?
sorry about the late…
i put a mesh like the terrain… is not regular… like irregular platforms
You can position the object anywhere, it doesn’t have to be on the XZ plane or anything like that.