|
| 09 Dec 2015 07:27 AM |
Hello. I am having a problem with raycasting to see if the player is getting close to a brick or not. Basically I am creating a part about 10 studs in front of the player and using that to raycast directly in front of the player.
local testPart2 = Instance.new("Part") testPart2.CFrame = CFrame.new(character.Torso.Position) * CFrame.Angles(character.Torso.CFrame:toEulerAnglesXYZ()) testPart2.CFrame = testPart2.CFrame * CFrame.new(0, 0, -10) local ray2 = Ray.new( character.Torso.Position, testPart2.Position ) local part2, endPoint2 = game.Workspace:FindPartOnRay(ray2, player.Character) if part2 and (endPoint2 - character.Torso.Position).magnitude < 10 and moveKeys() == true then character.Torso.CFrame = character.Torso.CFrame * CFrame.fromEulerAnglesXYZ(0.05,0,0) print(endPoint2) end
The problem I am having is that even though a wall is not in front of the player it still thinks it is and ends up doing the rotate from the final if statement. Is there anything wrong with my code? |
|
|
| Report Abuse |
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 09 Dec 2015 07:34 AM |
| Shouldn't a ray have a length too? |
|
|
| Report Abuse |
|
|
| 09 Dec 2015 09:05 AM |
The length is the distance between the two positions i.e. Players Torso Position Testpart2's position |
|
|
| Report Abuse |
|
|
| 09 Dec 2015 09:34 AM |
second argument is direction, not position
NOOB BISQUE |
|
|
| Report Abuse |
|