|
Hours have passed and I can't get this to work. I have a object with a empty object with box collider as a child so that I can get a sort of line of sight area, but I'm trying to get a raycast to be shot from the character to another character so that it can check for line of sight and it won't work. Whatever I try to do, the raycast only goes to the same direction which is 3 o'clock from the object that sends the raycast. Wth am I doing wrong?
(comments are locked)
|
etc.. same thing with the DrawRay, you need a direction, not a position Oh wow.. thanks, it worked. I gotta say maybe I need to get some sleep but I didn't quite get how's that different from having just one of those positions as a direction. Didn't you just subtract one position from another?
Aug 16 '12 at 01:52 PM
marcelomedeiros
what you need to understand is that a Vector3 can be used to represent both positions AND directions.. take for example Vector3(0,1,0) as a POSITION, this is 1 unit above the world origin, right near the center of the world as a direction, this is straight up (no matter what the position) so lets say my player is at some other position(say(1,1,1)), and I want the direction to my object at (0,1,0)... saying: if (Physics.Raycast(player.transform.position, Vector3(0,1,0) , hit, attackRange)) { means I want a ray starting at the player, in the direction straight up! but that's not right, I wanted the direction from my player to the target. Saying: (targetPosition - originPosition) gives us the relative direction, which is what the Ray uses (a DIRECTION, not a POINT) (0,1,0) - (1,1,1) = (-1,0,-1) in this case, the direction from my player to my target is Vector3(-1,0,-1).. this is quite different from (0,1,0)!
Aug 16 '12 at 02:12 PM
Seth Bergman
You sir, are the man. Thanks again!
Aug 16 '12 at 02:45 PM
marcelomedeiros
(comments are locked)
|

Do you want to send a Ray from point A to B?
I wanna send a ray from gameobject1 to the gameobject2 that collided with a specific box collider