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
 

:pointToObjectSpace

Previous Thread :: Next Thread 
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 08:08 PM
What does :pointToObjectSpace do?
Report Abuse
vat21s is not online. vat21s
Joined: 07 Jun 2010
Total Posts: 2508
30 Jul 2014 08:18 PM
Idk, Mabey rotates something to face something else.
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 08:30 PM
Taking cframe:pointToObjectSpace(vector3), the vector3 will be rotated as if the cframe's orientation was the world's orientation. It will also be translated (moved) to that cframe as if the cframe's x, y, z values were the world's origin.

So, say you had a 2x2x2 part and you wanted the coordinates of the top-right-front corner.

If this part were centered at (0,0,0) and had 0 rotation, it would just be (1, 1, -1), right?

So we take that vector and rotate it and move it over to the part's actual cframe:

print( Workspace.Part.CFrame:pointToObjectSpace(Vector3.new(1, 1, -1)) )
> Coordinates of right top front corner
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 09:27 PM
What's this world orientation thing?
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 09:42 PM
It's just like the normal axes, centered at the origin (0, 0, 0)
So when you set a part's position to be Vector3.new(10, 20, 30) - even though you may not know it - you're setting it in world space (or world orientation).
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 09:49 PM
Alright. Thanks.

Is it good to use in a tank turret script to make the turret or barrel turn/spin towards your mouse?
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 10:02 PM
I guess it's possible, but it's really not.

What if, instead, you used atan2 to get the spin angle and either atan2 or asin to get the up-down angle?

it would be something like this:

local aimVector = (mousePosition - turretPosition).unit
local spinAngle = math.atan2(-aimVector.X, aimVector.Z)
local elevationAngle = math.asin(aimVector.Y)
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 10:03 PM
Thanks! But this is what I have with objectSpace to far...

Vehicle.Main.Swivel1.Weld.C0 = CFrame.new(Vehicle.Main.Swivel1.Weld.C0.p, Vehicle.Main.Swivel1.CFrame:pointToObjectSpace(Vector3.new(Mouse.Hit.p.x, Vehicle.Main.Swivel1.Position.y, Mouse.Hit.p.z)))
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 10:07 PM
Also, I tried doing your way. Not working out so well. Is this how you wanted me to do it?

local aimVector = (Mouse.Hit.p - Vehicle.Main.Swivel1.Position).unit
local spinAngle = math.atan2(-Mouse.Hit.X, Mouse.Hit.Z)
local elevationAngle = math.asin(Mouse.Hit.Y)
Vehicle.Main.Swivel1.Weld.C0 = CFrame.new(Vehicle.Main.Swivel1.Weld.C0.p, Vector3.new(spinAngle))
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 10:09 PM
Not quite. I'll fix it, but what's the C0 set to without rotation?
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 10:15 PM
I never set anything to the C0. I just welded the swivel1 and connector1 together, so they pretty much are inside of each other. And then i'm using it now to make it turn. So the swivel1 is turning and the connector one is still.
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 10:20 PM
Cool OK

so here's your way revised. Your first way actually seemed like it might work, but whatever. Not sure if this works:

Vehicle.Main.Swivel1.Weld.C0 = CFrame.new(Vehicle.Main.Swivel1.Position, Vector3.new(Mouse.Hit.p.x, Vehicle.Main.Swivel1.Position.y, Mouse.Hit.p.z)) - Vehicle.Main.Swivel1.Position


Here's my way revised (probably works):

local aimVector = (Mouse.Hit.p - Vehicle.Main.Swivel1.Position).unit
local spinAngle = math.atan2(-aimVector.X, aimVector.Z)
local elevationAngle = math.asin(aimVector.Y)
Vehicle.Main.Swivel1.Weld.C0 = CFrame.Angles(0, spinAngle, 0)
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 10:29 PM
Your way doesn't make a specific side (preferably the front face) face the mouse at all times.

My way works, I had like a problem with it.

In a tank, there's the turret that spins left or right. This is what I used for it:

Vehicle.Main.Swivel1.Weld.C0 = CFrame.new(Vehicle.Main.Swivel1.Weld.C0.p, Vehicle.Main.Swivel1.CFrame:pointToObjectSpace(Vector3.new(Mouse.Hit.p.x, Vehicle.Main.Swivel1.Position.y, Mouse.Hit.p.z)))

The barrel, goes up and down. I used this script for it:

Vehicle.Turret.Swivel2.Weld.C0 = CFrame.new(Vehicle.Turret.Swivel2.Weld.C0.p, Vehicle.Turret.Swivel2.CFrame:pointToObjectSpace(Vector3.new(Mouse.Hit.p.x, Mouse.Hit.p.y, Mouse.Hit.p.z)))

Now, technically, if the turret is not spinning left or right, the barrel would follow your mouse in all rotations without limitations (because I didn't set any). I wanted to try and make the barrel go up and down only. I got it to work once, but if the turret moves left or right, the barrel kinda like bends left or right to rotate towards your mouse as the turret is spinning. It might be hard to picture in words, so would you like me to open up my tank place to see?
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 10:36 PM
Nevermind. Your way works fine, just the wrong side is facing your mouse. I tried making it:

local aimVector = (Mouse.Hit.p - Vehicle.Main.Swivel1.CFrame.lookVector).unit
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 10:44 PM
Don't change that line, change this line:

local spinAngle = math.atan2(-aimVector.X, aimVector.Z)

if you want to spin the whole thing around, you can change the signs or add 180 degrees:

local spinAngle = math.atan2(aimVector.X, -aimVector.Z)
or
local spinAngle = math.atan2(-aimVector.X, aimVector.Z) + math.pi

To change it 90 degrees, flip the sign for the X part or add math.pi/2
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 10:46 PM
Also,

Vehicle.Turret.Swivel2.Weld.C0 = CFrame.Angles(elevationAngle, 0, 0)

May need to make it negative/add math.pi also
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 11:05 PM
+ 100 respect points.
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 11:08 PM
Can you unlock the place? I wanna see lol
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 11:44 PM
Sure. It's vehicle testing. Press "Y" to get in.
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
30 Jul 2014 11:49 PM
it elevation angle is just kinda weird (i.e. it won't follow your mouse on time). It kinda gets stuck a little when looking down, it wouldn't budge the barrel all the way down like there's a barrier it has to pass. IDK why. The turning is great, though.
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
30 Jul 2014 11:56 PM
Because aimVector is going from the center of the swivel1, not from where the barrel is beginning:

local elevationAngle = math.asin((Mouse.Hit.p-Vehicle.Turret.Swivel2.Position).unit.Y)

Should fix it.
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
31 Jul 2014 12:26 AM
Thank you.
Report Abuse
ninja900500 is not online. ninja900500
Joined: 27 Sep 2008
Total Posts: 2324
31 Jul 2014 11:49 PM
By the way, I just noticed the surface-point-to-mouse fix does not work well when the tank is rotated in another way.
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