|
I'm working with a turret and i want to add in a target ring that lets you know where you are going to be shooting. I can get the turret to rotate and move guns back and forth. I've added the target ring and can get it to rotate and move back and forth. but it gets stuck in like ditches and gulleys I've made. I've made a simple cylinder for the target area and attached a rigid body and locked constraints on it except where i want it to rotate and move. I've given it gravity as well. I'm not sure how to code this part for making it go up the hills on the little paths I've made. this is the code i have so far split into two scripts. one rotates the entire turret the other just moves the ring back and forth along the Z axis. shotArea.cs (moves back and forth) rotation script: using UnityEngine; using System.Collections; public class turretbehave : MonoBehaviour { public Transform Shot; public float rotateRate = Mathf.PI /6; // 30 degrees per second public bool rotate = false; public GameObject turret; } thanks for any help.
(comments are locked)
|
|
First of all, if your goal is simply to project a marker onto a shape (your terrain), why not use a projector? You could move the projector around at a set height and the projected marker would perfectly follow the terrain. If for some reason you absolutely have to have an object follow the terrain, physics is definitely not the way to go. Physics is for simulations, where you don't know the outcome and want Unity to figure out the math. When you do know the outcome, as in your case ("I want the marker to be at this X and Z and whatever the height of the terrain is there as the Y"), you're much better off setting the position yourself. The easiest way to figure out the height is to use raycasting and point the ray straight down (e.g. (0, -1, 0)).
(comments are locked)
|
