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 » Scripting Helpers
Home Search
 

Re: How would I check if a part is 5 studs above my torso?

Previous Thread :: Next Thread 
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
22 Nov 2013 08:42 PM
if part.CFrame.Y >= workspace.Infocus.Torso.CFrame.Y then
--
end

Like that?


I cant test momentarily due to me being on an ipad.
Report Abuse
DrWaffler is not online. DrWaffler
Joined: 16 Sep 2011
Total Posts: 4248
22 Nov 2013 08:44 PM
I believe the only way is to cast a ray straight up.

At least I haven't heard of any other method, and I haven't really had need of checking what's above my head yet.

--[Territory Conquest Developer, Valerian Studios Developer, Business Casual Narwhal Moai. ]]--
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
22 Nov 2013 08:47 PM
DrWaffler, please refrain from posting on threads if you don't know the answer. You're only serving the purpose of misleading or confusing the OP.


OP, you would want to do something like this

local torsoY = character.Torso.Position.Y
local partY = part.Position.Y

if partY - torsoY == 5 then
...


Remember, difference is just another word for what you get when you subtract two numbers.
Report Abuse
DrWaffler is not online. DrWaffler
Joined: 16 Sep 2011
Total Posts: 4248
22 Nov 2013 08:51 PM
@Arceus

I believe he is only wanting if it is directly above his head.

The y coordinate could be the same, even if the X and Z aren't, so the brick could be 10,000 studs away, but 5 studs up from where his torso is on the y axis.

--[Territory Conquest Developer, Valerian Studios Developer, Business Casual Narwhal Moai. ]]--
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
22 Nov 2013 08:55 PM
"I believe he is only wanting if it is directly above his head."

If that's what he wants, all he needs to do is add a few more conditions to the check


local torsoX, torsoY, torsoZ = character.Torso.Position.X, character.Torso.Position.Y, character.Torso.Position.Z
local partX, partY, partZ = part.Position.X, part.Position.Y, part.Position.Z

if partY - torsoY == 5 and partX == torsoX and partZ == torsoZ then
...
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
22 Nov 2013 08:57 PM
Additionally, he could do this

local torsoP = torso.Position
local partP = part.Position
local idealDifference = Vector3.new(0, 5, 0)

if partP - torsoP == idealDifference then
...
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
22 Nov 2013 09:15 PM
I appreciate the help ^^
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Nov 2013 10:14 PM
You should also compare it with the size of the torso and the part, so you don't have to be perfectly and exactly right under it
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
22 Nov 2013 10:33 PM
and dem floats shud b rounded.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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