mattscyJoin Date: 2011-05-06 Post Count: 1079 |
how would you determine the face of the part the mouse is hovering over, despite the rotation of that part?
so if you had a part and you hovered over one of the sides, it would print "Front"
and then if you rotated the part 90 degrees and then hovered over the new face that is on the same side, it would still print "Front"
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
You could take the magnitude from each of the face centers - mouse.Hit.p
Alternatively you could cast that hits the face, and return its normal, then compare that normal with the upVector,-upVector,lookVector,-lookVector,rightVector,-rightVector and see which one it's closest to (or matches) |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
NormalId
TargetSurface [readonly]
The side of the instance that the mouse is pointing to.
http://wiki.roblox.com/index.php?title=API:Class/Mouse
No need for raycasting Soy.
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
Niiiiice.
I'm used to determining this without a mouse. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
Yeah lol. Good for practice too :D But for beginners the mouse can be of assistance.
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
Only potential downside to using this parameter of the mouse that I can see is if you need to verify it on the server, and it's something that should be secure.
In all likelihood, for you, it's not. |
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
using this property* |
|
mattscyJoin Date: 2011-05-06 Post Count: 1079 |
i am aware of targetsurface, but that returns the surface relative to the parts rotation
what i need is a way to determine which face on the part is facing north, south, east, west etc. despite the rotation
for example, using targetsurface, if you hover over the front of the part it says Front
then when you rotate it 90 degrees the surface that is now facing in that direction would be the Right
but i want it so that both times, no matter what the rotation, the surface thats pointing in that direction (or closest to that direction) will print as front |
|
|
well if you rotate the part its no longer the front so? |
|
mattscyJoin Date: 2011-05-06 Post Count: 1079 |
it would be the front in world space |
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
If you are trying to determine which face of a part is most facing north (or any direction), you would supplement the worldly direction's unitvector and each of the part's face's unitvectors until you find the closest into this function that determines the angle between two vectors:
math.acos(a:Dot(b)) |
|
mattscyJoin Date: 2011-05-06 Post Count: 1079 |
so far i have this, although when i print all of them out they are either 0 or half of pi
local north = Vector3.new(0,0,1)
local front = math.acos(mouse.Target.CFrame.lookVector:Dot(north))
local back = math.acos(-mouse.Target.CFrame.lookVector:Dot(north))
local right = math.acos(mouse.Target.CFrame.rightVector:Dot(north))
local left = math.acos(-mouse.Target.CFrame.rightVector:Dot(north))
local up = math.acos(mouse.Target.CFrame.upVector:Dot(north))
local down = math.acos(-mouse.Target.CFrame.upVector:Dot(north))
what am i doing wrong?
|
|
SoybeenJoin Date: 2010-02-17 Post Count: 21462 |
Could the issue be your order of operations?
local back = math.acos(-mouse.Target.CFrame.lookVector:Dot(north))
versus
local back = math.acos((-mouse.Target.CFrame.lookVector):Dot(north)) |
|
mattscyJoin Date: 2011-05-06 Post Count: 1079 |
still doesnt work
also tried north:Dot(mouse.Target.CFrame.lookVector) but that doesnt seem to work either
|
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
1. Show us the 'if' statements. 2. Dot product is commutative, meaning that either way the result will be the same as the function simply returns #### # #### + v1.Y * v2.Y + v1.Z * v2.Z. |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
(-a).b == (a).(-b) == -(a.b)
So that isn't the issue.
"so far i have this, although when i print all of them out they are either 0 or half of pi"
Angle of 0 means the vectors are parallel... Angle of half of pi means they are perpendicular.
I'm not entirely sure what you want but,
if you're looking for a way to determine which surface is the closest to facing that direction of Vector3.new(0,0,1)... Use this;
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=227496670
Once you get the code for the function up, replace Vector3.new(0,1,0) with Vector3.new(0,0,1).
|
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
Woops...
I meant, replace each .y with a .z
(There are two of them.) |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
Basically...
the one that produces an angle of 0 is parallel to the vector (0,0,1).
It is the equivalent of testing each face and seeing which dot product value is the closest to 1.
(As acos(1) == 0) |
|