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
|
  |
| Joined: 20 Jan 2009 |
| Total Posts: 240 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 04 Apr 2017 03:17 PM |
ez
object.CFrame = (part.CFrame - part.CFrame.p) + object.CFrame.p |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2017 03:18 PM |
| also lookVector is the direction, not the angles .-. read up more on cframe |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 20 Jan 2009 |
| Total Posts: 240 |
|
| |
|
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 |
|
|
|
| 05 Apr 2017 07:33 PM |
| or u can just add the position to the rotation lol |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 05 Apr 2017 09:44 PM |
| i know but that wont give it the same roll |
|
|
| Report Abuse |
|
|
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 |
|
|
| |
|
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
|
  |
| Joined: 09 May 2015 |
| Total Posts: 13095 |
|
| |
|
|
| 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
|
  |
| 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 |
|
|