I want to use another object and be an exact distance away from it.
What I want basically is my position to be +2 on the y axis alongside the other object
I raycast down, to see where the object is (in this time the object itself is falling) when it reaches it I want it to take it’s place +2 on the y axis from the object it’s raycasting on
Here is what I have so far
void FixedUpdate(){
RaycastHit hit;
Vector3 otherObjectPosition;
//Vector3 direction = transform.TransformDirection(-Vector3.up);
if (Physics.Raycast(transform.position, -Vector3.up, out hit, 2, ~layerToIgnore)){
otherObjectPosition = hit.collider.gameObject.transform.position;
Vector3 temp = transform.position;
// transform.position.y = otherObjectPosition.y -= -2;
temp.y = otherObjectPosition.y -= 2;
} else {
MoveDown();
}
}
public void MoveDown(){
transform.Translate(Vector3.down * Time.deltaTime, Space.World);
}
Can someone help me with this because it isn’t doing what I’m expecting to do and I can’t seem to get it to work.
Thanks,
Jan Julius.