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: Rotate objects relative to lookVector

Previous Thread :: Next Thread 
florodude is not online. florodude
Joined: 20 Jan 2009
Total Posts: 240
04 Apr 2017 02:45 PM
Hey all, I'm having problems rotating objects relative to lookVector. Simply put, my projectiles are firing in the direction I'm looking, but the rotation isn't working. I need to slighty adjust rotation as it, so the code I have looks like:

object.Rotation = player.Character.Torso.CFrame.lookVector + Vector3.new(0,0,90)

But yet the object is always facing the same way no matter which direction I shoot it. Anybody have any thoughts?
Report Abuse
florodude is not online. florodude
Joined: 20 Jan 2009
Total Posts: 240
04 Apr 2017 02:59 PM
bump
Report Abuse
Atavis is not online. Atavis
Joined: 10 Apr 2012
Total Posts: 1463
04 Apr 2017 03:00 PM
Rotation often resolves unexpectedly. But I have no idea why that doesn't work lol

object.CFrame = object.CFrame*player.Character.HumanoidRootPart.CFrame.lookVector + Vector3.new(0, 0, 90)
might be completely wrong lol but still a suggestion ^


117,322 slices of pizza and counting!
Report Abuse
florodude is not online. florodude
Joined: 20 Jan 2009
Total Posts: 240
04 Apr 2017 03:16 PM
Yeah I don't think that works, sorry:/ any other thoughts?
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
04 Apr 2017 03:17 PM
ez

object.CFrame = (part.CFrame - part.CFrame.p) + object.CFrame.p
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
04 Apr 2017 03:18 PM
also lookVector is the direction, not the angles .-. read up more on cframe
Report Abuse
Atavis is not online. Atavis
Joined: 10 Apr 2012
Total Posts: 1463
04 Apr 2017 03:21 PM
Will do xD


117,285 slices of pizza and counting!
Report Abuse
florodude is not online. florodude
Joined: 20 Jan 2009
Total Posts: 240
04 Apr 2017 03:23 PM
Wait, what's the difference between object cframe and part in that analogy? How does the player's position play in? And this has to do with rotation, right?
Report Abuse
florodude is not online. florodude
Joined: 20 Jan 2009
Total Posts: 240
04 Apr 2017 03:35 PM
bump
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
04 Apr 2017 03:59 PM
If you mean rotate objects along the axis of the lookVector, you can use the CFrame.fromAxisAngle constructor here:
local cf = CFrame.new(pos) * CFrame.fromAxisAngle(obj.CFrame.lookVector, angle)

But after rereading what you want, that's not what you wanted at all.
"object.Rotation = player.Character.Torso.CFrame.lookVector + Vector3.new(0,0,90)"
Alright so firstly lookVector is a Vector3, the direction the -Z (front surface of part) is facing. What you can do, and what most people do, is use the CFrame constructor that accepts 2 vectors:
CFrame.new(pos, posToLookAt)

So in your case:
projectile.CFrame = CFrame.new(position, position+barrel.CFrame.lookVector)
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Apr 2017 07:33 PM
or u can just add the position to the rotation lol
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Apr 2017 09:44 PM
That's different, so no. This CFrame constructor keeps "up" as "up" so will choose the "better" solution instead of just setting the rotation where up may point down it tries to keep up as up.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Apr 2017 09:44 PM
i know but that wont give it the same roll
Report Abuse
Arkitek is online. Arkitek
Joined: 09 May 2015
Total Posts: 13095
06 Apr 2017 12:49 AM
"object.CFrame = (part.CFrame - part.CFrame.p) + object.CFrame.p"


what's the p mean?

I'm new to scripting
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Apr 2017 12:49 AM
vector3
cframes position
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Apr 2017 12:50 AM
`p` is a property of `CFrame` objects that return the positional part as a `Vector3`.
Report Abuse
Arkitek is online. Arkitek
Joined: 09 May 2015
Total Posts: 13095
06 Apr 2017 12:50 AM
o ty
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Apr 2017 12:51 AM
mine subtracts its position so it returns a cframe at 0,0,0 with its old rotation, then it moves it over to the objects location
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Apr 2017 12:55 AM
Yes but I already explained why that could yield unexpected results:
Here if you need a visualization
puu.sh/vaWGc/fc62ea21ef.mp4
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