Been trying to have a gun,or indeed anything like a simple block to use as one,to follow the player, the player in this case is a character controller using physics,I have the player moving using th left joystick to move the character controller whilst the right joystick rotates the character controller, the camera simply gets set to the position of the controller and its rotation set to that of the player every loop:
So this is what I have so far:
repeat
print (str(cameradistance#))
if active=1
print("player active")
endif
if movleft=0 and movright=0 and movup=0 and movdown=0
Move3DPhysicsCharacterController( Player, Direction_Stop, CamSpeed# )
endif
Step3DPhysicsWorld()
w#= GetRawMouseWheelDelta()
if w#<0
cameradistance#=cameradistance#+6
endif
if w#>0
cameradistance#=cameradistance#-6
endif
//camcontrol()
if getrawkeypressed(KEY_E)
quit=1
endif
jx#=GetVirtualJoystickX (1)
jy#= GetVirtualJoystickY(1)
jx2#=GetVirtualJoystickX (2)
jy2#= GetVirtualJoysticky(2)
if jx2#<0
Rotate3DPhysicsCharacterController( player,ang#)
//setobjectrotation(gun,getobjectanglex(gun),getobjectangley(gun)-ang#,getobjectanglez(gun))
ang#=ang#-1
if ang#<0
ang#=360
endif
endif
if jx2#>0
Rotate3DPhysicsCharacterController( player,ang#)
ang#=ang#+1
if ang#>360
ang#=0
endif
endif
if jy2#<0
inc angxoff
RotatecameraLocalY(1,1)
endif
if jy2#>0
dec angxoff
RotatecameraLocalY(1,-1)
endif
if jx#<0 and jy#<0
//movleft=1
//movup=1
endif
if jx#>0 and jy#>0
//movRight=1
//movup=1
endif
if jy#<0
movup=1
movdown=0
endif
if jy#>0
movdown=1
movup=0
endif
if movup>0
print("up")
Move3DPhysicsCharacterController( Player, Direction_Backward, CamSpeed# )
endif
if jx#=0
movleft=0
movright=0
endif
if movdown>0
print("up")
Move3DPhysicsCharacterController( Player, Direction_forward, CamSpeed# )
endif
if jx#<0
//movleft=1
//movright=0
endif
if jx#=0
movleft=0
movright=0
endif
if movleft>0
Move3DPhysicsCharacterController( Player, Direction_Left, CamSpeed# )
//SetObject3DPhysicslinearVelocity( playerobject, 1, 0, 0, 5+abs(g#) )
endif
if jx#>0
//movright=1
//movleft=0
endif
if jx#=0
movright=0
movleft=0
endif
if jy#=0
movup=0
movdown=0
endif
if movright>0
Move3DPhysicsCharacterController( Player, Direction_Right, CamSpeed# )
//SetObject3DPhysicslinearVelocity( playerobject, -1, 0, 0, 5+abs(g#) )
endif
if getrawkeypressed(key_space)
jump3DPhysicsCharacterController(player)
endif
SetPointLightPosition(1,getobjectx(player),getobjecty(player)+34,getobjectz(player))
SetCameraRotation(1,GetObjectAngleX(player),GetObjectAngley(player),GetObjectAnglez(player))
setcameraposition(1,getobjectx(player),getobjecty(player)+30+CameraDistance#,getobjectz(player)+2)
//
//setobjectposition(gun,getcamerax(1),getcameray(1),getcameraz(1)-5)
//SetobjectRotation(gun,GetObjectAngleX(player)-angxoff,GetObjectAngley(player),GetObjectAnglez(player))
//SetCameraLookAt(1,getobjectx(player),getobjecty(player),getobjectz(player),0)
sync()
Until quit=1
The code has gotten a little messy as I was trying different stuff!
I just need to somehow get a gun to follow and rotate correctly with everything else!
Hail to the king, baby!