- Home /
[Closed] Instantiate wall/fence down a raycast from point A to point B?
I need to be able to create a wall from point A to point B between two placeable marker points. This is what i have on Point A marker:
#pragma strict
//point B Marker
var target: Transform;
public var Wall: Transform;
var create = false;
function Start () {
}
function Update () {
if(create == true){
var relativePos = target.position - transform.position;
var distance = Vector3.Distance(target.position, transform.position);
var ModelsNeeded = distance / 10.0;
print ("Distance to other: " + distance);
for (var i : int = 0;i < ModelsNeeded; i++) {
Instantiate (Wall, Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.LookRotation(relativePos));
create = false;
}
}
if(Input.GetKeyUp("space")){
create = true;
}
transform.LookAt(target);
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast (transform.localPosition, fwd, hit, Mathf.Infinity)) {
Debug.DrawRay (transform.position, fwd * hit.distance, Color.green);
}
}
what this does right now is it allows me to get the distance between point A and point B, but only instantiates wall at point A position. I need it to follow the raycast all the way down to point B. I hope that makes sense thanks. - Brady
So the line that the problem is on i believe is at line 26. On this line i have it where when it instantiates all the walls created are at position point A marker and does not follow to point B marker? What to i need to Find var wise or what do i need to change?
another note is that the wall is 10 units wide and i want to instantiate down a say 50 unit long distance... so i will need 5 walls segments.
You're not offsetting the walls you instantiate by their width. Are you sure that there aren't 10 segments all in the same place?
Also, ins$$anonymous$$d of setting a flag to check every frame, just make a method that creates wall segments. When the space key goes up, just call the method.
Hmm...Heres how i have it right now. When I click on the terrain/plain it creates $$anonymous$$arker A. Ill move the mouse and click again which creates marker B. I want to be able to create wall segments between $$anonymous$$arker A and $$anonymous$$arker B. So what do i need to use?
Your answer
Follow this Question
Related Questions
Instantiate gameobject a certain distance away from transform 2 Answers
Position before the camera? 2 Answers
Distribute terrain in zones 3 Answers
How do i instantiate along the z axis? 3 Answers