generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Raycasting problem?

Previous Thread :: Next Thread 
curtisornot is not online. curtisornot
Joined: 30 Jun 2008
Total Posts: 1271
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 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
09 Dec 2015 07:34 AM
Shouldn't a ray have a length too?
Report Abuse
curtisornot is not online. curtisornot
Joined: 30 Jun 2008
Total Posts: 1271
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
DermonDarble is not online. DermonDarble
Joined: 04 Jun 2015
Total Posts: 2576
09 Dec 2015 09:34 AM
second argument is direction, not position

NOOB BISQUE
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image