|
| 06 Aug 2014 02:23 PM |
I'm making some parkour stuff for my friend, and I want it so you have to be facing this "Bar" I have to jump over it.
How do I do this? |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 02:27 PM |
using the dot product, you can say:
function dot(unit1,unit2) return (unit1.X*unit2.X)+(unit1.Y*unit2.Y)+(unit1.Z*unit2.Z) end
function isFacing(part1,part2) if dot(part1.lookvector,(part2.Position-part1.Position).Unit)<=.3 then return true end return false end
if isFacing(Character.Head,Parkourpart) then --facing code end |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 02:28 PM |
| I hate just taking things from people, can you explain the math? |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 02:33 PM |
sure. Basically, you get to Vector Units, so basically 2 directions.
what the math does is it returns a value -1 to 1, where -1 means the Units (Directions) are opposite, and 1 means they are facing eachother.
The dot function i provided is simply the equation to derive the (-1 to 1)
so, in this case all i did was took the lookVector of the first brick (aka its facing direction) (which is already in terms of a Unit length) and took the direction of the head to the parkour brick and compred the two with the "dot product" function. Hence, if the dot of the two vectors is <=.3 they are i within .3 ellipsoid of facing the same direction. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 02:35 PM |
| I mis spoke. getting -1 means they are facing opposite directions, and getting 1 means they are facing the same direction, so (north,north) [ex] is 1 and (south,north) is -1. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 02:54 PM |
Well I accidentally closed out of studio without saving twice after testing because this new studio is horrible and the creator should be burned on a Wooden stake.
I found a glitch before I left though, it only worked when I stood on top of the bar, didn't matter if I was looking at the center of it either.
But was I was thinking is could I send a raycast from x axis of the torso but the y and z axis of the bar, from the torso to the bar, could that work? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 02:56 PM |
Yeah you could just do raycast if you really want.
local isFacing = function(part, part2) return Workspace:FindPartOnRay(Ray.new(part.Position, part.lookVector * 1000)) == part2; end; |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 06:09 PM |
@cnt, that is assuming that something is not already in the way and that your raycast has to hit it to be considered "facing" it-
No offense towards your method of doing this but i do believe my method gets the job done better to a certain degree. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Aug 2014 06:53 PM |
| I never said your method sucked, I just showed him how he could of done it with raycasting |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 08:21 PM |
I need help figuring out which side part the torso is in, I already started it and I was thinking of comparing each value than do some magic math and pop it comes out, but I can't figure out how..
local ix=item.Position.X local iy=item.Position.Y local tx=torso.Position.Y local ty=torso.Position.Y if ix then end |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 08:22 PM |
| You should also change Y to Z |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2014 08:26 PM |
I did this, what now?
local ix=item.Position.X local iz=item.Position.Z local tx=torso.Position.X local tz=torso.Position.Z if ix > tx then print("ix") end if iz > tz then print("iz") end if tx > iz then print("tx") end if tz > ix then print("tz") end |
|
|
| Report Abuse |
|
|