Jump to content

Controlling my controller


fumanshoo
 Share

Recommended Posts

so I've been working on a first person controller, and I fixed a few things, but I'm stuck with one last problem if you guys would be so kind to help out.The problem is that the controller goes backwards, forwards, left right like it should, but when I turn the controller, I realize that the "WASD" keys are moving the controller according to the world, rather than the controller. So if I look diagonally, It still goes backwards or forwards according to the world... here's the script

 

 

 

require("Scripts/constants/engine_const")

 

COLLISION_CHARACTER=1

 

RegisterAbstractPath("")

 

Graphics(800,600)

 

fw = CreateFramework()

 

camera = fw.main.camera

camera:SetPosition(Vec3(3,2,-10))

 

light = CreateDirectionalLight()

light:SetRotation(Vec3(45,45,0))

 

scene = LoadScene("abstract::animation_test_lab.sbx")

scene:SetCollisionType(1)

scene:SetRotation(Vec3(0,90,0))

 

controller = CreateController(1.8,0.3,0.5 , 45)

controller:SetMass(5)

controller:SetCollisionType(COLLISION_CHARACTER)

controller:SetPosition(camera)

controller:Move(Vec3(0,1,0))

 

DebugPhysics(0)

 

MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

camRotation = Vec3(0)

dx = 0.0

dy = 0.0

 

strafe = 0

move = 0

 

while KeyHit(KEY_ESCAPE)==0 do

 

mx=Curve(MouseX()- GraphicsWidth()/2,3.0/AppSpeed())

my=Curve(MouseY()- GraphicsHeight()/2,3.0/AppSpeed())

MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

camRotation.x = camRotation.x + my / 8

camRotation.y = camRotation.y - mx / 8

camera:SetRotation(Vec3(camRotation.x,camRotation.y,1))

 

move = Curve( (KeyDown(KEY_W)-KeyDown(KEY_S)) * 5, move , 3 )

strafe = Curve( (KeyDown(KEY_D)-KeyDown(KEY_A)) * 5, strafe , 3 )

 

controller:Update(0, move, strafe, jump, 25 , 10)

 

fw:Update()

 

camera:SetPosition(Vec3( controller.position.x, controller.position.y, controller.position.z ))

 

fw:Render()

 

Flip(0)

end

Link to comment
Share on other sites

you need the Y angle value of the camera in the angle parameter of the Update controller command.

 

controller:Update(camRotation.y, move, strafe, jump, 250 , 1, 0)

Also you might want to increase the maxacceleration parameter from 25 to something significantly higher, unless you want a sliding effect.

 

Also the camera position has to be offset from the controller, otherwise the camera is placed at the ground level.

camera:SetPosition(Vec3( controller.position.x, controller.position.y+1.8, controller.position.z ))

 

and this line does nothing:

controller:SetPosition(camera)

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...