Jump to content

Third Person Cam Help


fumanshoo
 Share

Recommended Posts

Hey, so I'm working on my first ever third person cam in Leadwerks and everything works fine except the fact that when I turn my camera, I can never see the front of my character because as my camera turns, so does my character. I have no idea how to fix this, and I assume it has something to do with parenting the character to the camera pivot, but I don't think that's right at all... I saw something a lot like this on Scarlet Thread's YouTube page which was very interesting, but I have no clue as to how it's done.... here's what I have...

 

require("Scripts/constants/engine_const")

require("Scripts/math/math")

 

COLLISION_CHARACTER=1

 

RegisterAbstractPath("")

 

Graphics(800,600)

 

fw = CreateFramework()

 

camera = fw.main.camera

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

 

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

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

 

-- size^^^ angle^

controller = CreateController(1,.15,.15 , 45,.5)

controller:SetMass(5)

controller:SetCollisionType(COLLISION_CHARACTER)

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

 

steamPunk = LoadModel("abstract::steampunk chick re-rig.gmf")

steamPunk:SetPosition(Vec3(0,0,0))

steamPunk:SetRotation(Vec3(0,180,0))

steamPunk:SetScale(Vec3(.6,.6,.6))

steamPunk:SetParent(controller)

 

steamPunkPivot = CreateController

 

DebugPhysics(1)

 

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

camRotation = Vec3(0)

dx = 0.0

dy = 0.0

 

SetWorldGravity(Vec3(0,-20,0))

 

strafe = 0

move = 0

 

--Third person pivot

controllerPivot = CreatePivot(controller)

camera:SetParent(controllerPivot)

 

while KeyHit(KEY_ESCAPE)==0 do

 

--jump

jump = KeyHit(KEY_SPACE) * 6

if controller:IsAirborne()==1 then

jump = 0

end

 

if KeyDown(KEY_RALT)==1 then

camera:SetPosition(Vec3(0,1,-1))

else

camera:SetPosition(Vec3(0,1,-2))

end

 

--spawn

if KeyDown(KEY_X)==1 then

steamTap = LoadModel("abstract::steampunk chick re-rig.gmf")

steamTap:SetScale(Vec3(5,5,5))

steamTap:SetPosition(Vec3(0,0,0))

end

 

--crouch

if KeyDown(KEY_LSHIFT)==1 then

controller:Crouch(1)

cameraHeight = 0.3

moveSpeed = 3

strafeSpeed = 3

else

controller:Crouch(0)

cameraHeight = .5

moveSpeed = 1

strafeSpeed = 1

end

 

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

 

--setting the minimum and maximum camera angles

camRotation.x = math.min(camRotation.x, 45)

camRotation.x = math.max(camRotation.x, -15)

 

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

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

 

controller:Update(camRotation.y, move * moveSpeed, strafe * strafeSpeed, jump, 25, 10, KeyDown(KEY_LSHIFT))

 

fw:Update()

 

controllerPivot:SetRotation(camRotation,1)

 

fw:Render()

 

Flip(0)

end

 

It's pretty fun messing around with camera stuff. Like the super basic camera zoom-in effect I made, but It's still no where near perfection.

Link to comment
Share on other sites

I haven't done this before but it seems like it can be done by having an extra dummy object. Meaning you'd have the camera parented to the dummy object which is then parented to the character. That way, you can rotate the dummy object which rotates the camera around the character but not the character itself. But rotating the character would rotate both, unless you unparent the dummy object. Hope that makes sense.

  • Upvote 1
Link to comment
Share on other sites

Yeah. I never see the front view of my character. Thought of using RotateEntity unless someone knows better.

 

EDIT: You could just use rotateentity with a flag that sets "turned" to true or false.When a certain key is pressed.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

I did what you told me, gamecreator, and got the exact opposite results haha. The character spins around the camera pivot when I move my mouse rather than the camera doing so. I no longer have time to work on this today, but I'll see if I get it right tomorrow... here's what I changed...

 

dummyObject = CreateCube()

dummyObject:SetPosition(Vec3(0,.5,0))

dummyObject:SetScale(Vec3(.5,.5,.5))

dummyObject:SetParent(controllerPivot)

 

 

controllerPivot = CreatePivot(controller)

camera:SetParent(dummyObject)

Link to comment
Share on other sites

I haven't done this before but it seems like it can be done by having an extra dummy object. Meaning you'd have the camera parented to the dummy object which is then parented to the character. That way, you can rotate the dummy object which rotates the camera around the character but not the character itself. But rotating the character would rotate both, unless you unparent the dummy object. Hope that makes sense.

 

This is the general idea. Although there are ways to do it without a pivot... I'll still explain using one.

 

Camera is parented to a pivot which is positioned (not parented) to the character. The reason you don't parent the pivot to the character is because if you do, you lose any possibility of smoothing.

 

For a good smooth camera you need to position the pivot at the characters position each frame except using the Curve function.

 

@Foomanshoo..

 

1. Create you objects: (this is psuedo code so not correct syntax)

LE::TCamera cam = CreateCamera();

LE::TPivot camPiv = CreatePivot();

LE::TController player = LE::CreateController();

 

2. LE::EntityParent(cam, camPiv); //Parent the camera to the pivot

 

3. LE::MoveEntity(cam, LE::Vec3(0, 0, -followDistance)); // Move the camera back by a certain distance

 

4. In Main Loop Position campPiv to Position of player except using the Curve smoothing function.

5. Also in main loop use user input from mouse movement to rotate the Turn the pivot allowing orbit around the point.

 

There are better ways to do this without a pivot but this should be easiest for you.

  • Upvote 1

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

ok, so I created a dummy object ( a cube in this case ) and parented it to my character and then my camera is parented to a pivot which is at the position Vec3(0,0,0) which is where my character is. My result is that my character spins along the y axis ( basically she spins like a ballerina ) and my camera no longer follows the character and just stays in one place. I guess this is an accomplishment but still not perfection. Here's what I changed in the code for this...

 

 

dummyObject = CreateCube()

dummyObject:SetPosition(Vec3(0,.5,0))

dummyObject:SetScale(Vec3(.5,.5,.5))

dummyObject:SetParent(steamPunk)

 

 

controllerPivot = CreatePivot(Vec3(0,0,0))

camera:SetParent(dummyObject)

Link to comment
Share on other sites

what are you calling TurnEntity on?

 

Also forget the dummyObject... I don't see what purpose it has. The pivot is supposed to be the dummy object itself that is parented to the player and then the camera is parented to the pivot. From what you're showing there it looks like you are creating a pivot and not doing anything with it.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

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...