Cuyler
|
  |
| Joined: 27 Feb 2006 |
| Total Posts: 3784 |
|
|
| 09 Apr 2016 11:35 AM |
I have a part I'm trying to move with a controller thumbstick, but movement of the part needs to change based on the rotation of the camera.
Basically, when I hold up on the control stick, even if I rotate the camera, the part will move forward on the camera, same with left/right.)
I tried something along the lines of:
object.CFrame = object.CFrame * CFrame.new(Vector3.new(gamepad_xPos, 0, gamepad_yPos) * camera.CFrame.lookVector)
This just prevents movement on a certain axis based on what rotation the camera has. What is the correct way to calculate the CFrame needed?
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 09 Apr 2016 12:13 PM |
If u mean in the direction of the camera but at the position of an object then,
Object.CFrame = (Camera.CFrame - Camera.CFrame.p) + Object.Position |
|
|
| Report Abuse |
|
|
Cuyler
|
  |
| Joined: 27 Feb 2006 |
| Total Posts: 3784 |
|
|
| 09 Apr 2016 12:24 PM |
Thanks, but that's not really what I wanted. I want the axis of movement to stay relative to the camera's rotation on an object which is controlled by a gamepad thumbstick. Basically, I can get it to move right when the camera is rotated a specific way, but if I rotate the camera at all on the y axis, the controller input directions differ from the direction that the object is moved. Here's a gif of it:
https://gyazo.com/d53a33e7da78f06b2b47be37b5677cd7
It works correctly until the camera is rotated in that gif, then the controls (x and z movements) get reversed.
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 09 Apr 2016 12:37 PM |
| So u want it to stay in front of the camera and always rotate relative to the camera, but don't want the height to go up due to the camera looking higher? |
|
|
| Report Abuse |
|
|
Cuyler
|
  |
| Joined: 27 Feb 2006 |
| Total Posts: 3784 |
|
|
| 09 Apr 2016 12:40 PM |
No, the object is supposed to be moved anywhere. You know how when you rotate your camera in game then press W you walk in the direction that your camera was rotated in? I want it to work similar to that. Basically:
When the camera rotates, up on the thumbstick will move it in the direction the camera is facing. Right now it is a constant direction, regardless of what direction the camera is facing.
|
|
|
| Report Abuse |
|
|
|
| 09 Apr 2016 12:42 PM |
Object.CFrame = Workspace.CurrentCamera.CFrame * CFrame.new(0,0,10)
??
Instance.new("BodyThrust",SenseiWarrior).position = CFrame.new(SenseiWarrior,YourGirlsDMs) |
|
|
| Report Abuse |
|
|
Cuyler
|
  |
| Joined: 27 Feb 2006 |
| Total Posts: 3784 |
|
|
| 09 Apr 2016 12:46 PM |
Sorry, I'm really bad at conveying my thoughts.
I want the object to be moved by the input from the thumbstick, but have the direction it is moved stay in sync with the direction the camera is facing. So if the camera is facing the -Z-Axis, then Up on the Thumbstick will move the object towards the -Z-Axis. Right now, if the camera faces any direction other than +X-Axis, it doesn't move in the facing direction, but rather always Up=+X, Down=-X, Left=-Z, Right=+Z.
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 09 Apr 2016 12:49 PM |
local cf = Camera.CFrame local left = cf:vectorToWorldSpace(Vector3.new(-1, 0, 0)) --I think it's vectorToWorldSpace() local right = cf:vectorToWorldSpace(Vector3.new(1, 0, 0)) local back = cf:vectorToWorldSpace(Vector3.new(0, 0, -1)) local front = cf:vectorToWorldSpace(Vector3.new(0, 0, 1))
if moving_left then --Just small example Object.CFrame = Object.CFrame + left end |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 09 Apr 2016 01:00 PM |
| So did it work or does it need fixing? |
|
|
| Report Abuse |
|
|
Cuyler
|
  |
| Joined: 27 Feb 2006 |
| Total Posts: 3784 |
|
|
| 09 Apr 2016 01:31 PM |
Thanks, that worked with a little modification. I had the Z-Axis rotated and had to create a CFrame with only the Y-Axis rotated, which fixed it.
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 09 Apr 2016 01:37 PM |
| Np ;) I'm happy to find out I didn't forget all my CFraming skills/memories from the time when I stopped developing for a while :D |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2016 01:38 PM |
| I was gonna say, this was probably somewhere in the default ControlScript somewhere anyway |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 09 Apr 2016 01:42 PM |
Yeah, but everyone is lazy to look through them XD (Including me) I only looked at them briefly once, long time ago, not much interesting stuff there. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2016 01:45 PM |
I just created a new one last night for my RTS.
My CameraScript is literally this because the "character" becomes the camera in my control script anyway lol:
--[[ @Author: DiamondBladee @Description: Replaces default camera script due to name. Do nothing. @Date: 8 April 2016 --]]
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
| |
|