pivots,cameras

Blitz3D Forums/Blitz3D Beginners Area/pivots,cameras

Ruz(Posted 2003) [#1]
Hi, i am just looking in to setting up a 3rd person camera view. To start i just want to have my player model in the camera view, the camera following rigidly behind( as a test)

I tried to parent the player model to the camera, which works to a degree. But if my player collides with a wall, the camera folllows straight after( and stays there)

I want the distance betweeen camera and player model to stay fixed, even if player model collides with the scenery

I am also getting confused mainly with the pivot , camera, playermodel relationaship here.
Which should be the overall parent in the hiercrachy?
Does the camera rotate around the pivot or the player model. Are the player model and pivot in the same place.

Another problem is becase the playermodel/camera has a collision radius, my player model is floating in the air. i can't translate it in the y axis, because the collision radius stops it going to the ground level.

I am very confused here.


Ross C(Posted 2003) [#2]
parent the camera to the player. then move the camera back say 10 units. The camera being parented to the camera meaning when the player moves the camera will move as if joined. but when the camera moves the player will not. the child will basically follow the player where-ever it goes.

could you post some code? i think i may have helped you out last time. won't be able to look at this for another 12 hrs. got to sleep then work. oh and remember you can reduce the collision radius of the player as well.

ps. the code i gave you was based on dr av's cam system which uses pivots for a smooth movement.


Ruz(Posted 2003) [#3]
Yes i looked through quie a bit of sample code for cameras, but since they were done in lots of different ways, i got confused. I am still very new to blitz and coding in general
its odd I need to have a mental image of what is going on exactly in a scene or I can't understand it.
i will fiddle around a bit more and then post my code, cheers


Ruz(Posted 2003) [#4]
heres a little test i was doing. the cone moves forward but the camera doesn't. i thought parenting the camera to the cone would mean it would follow it

Graphics3D 800,600,16,2
SetBuffer BackBuffer()

Const FPS=30


Cam1=CreateCamera()
EntityParent Cam1,cone


light=CreateLight()


; Create cone
cone=CreateCone()


PositionEntity cone,0,0,10


While Not KeyDown( 1 )

If KeyDown(200) Then MoveEntity cone,0,0,.3

UpdateWorld
RenderWorld
Flip
Wend


WolRon(Posted 2003) [#5]
Silly, you created the cone AFTER you parented the camera to it SO, you didn't actually parent the camera to it.

Here's why: The variable CONE equals zero at the start of the program. You parented the camera to the variable CONE but since the variable CONE equals zero you ended up parenting the camera to zero (i.e. nothing).
Only then do you create the cone and assign its handle to the variable CONE. If you were to parent the camera to it now, then it would actually be parented to the cone.


Ruz(Posted 2003) [#6]
hooray , thanks for that. The reason sid that is partly carelessness and maninly that my main program is laid out in a cnfusing manner, but mainly carelesness. But hey it works now .


Ruz(Posted 2003) [#7]
Right, the problem is now is that the camera can still rotate around its own axis, meaning that sometimes the player model is off to the side or behind me. how do fix that?I tried pointing the camera to the player model

PointEntity camera,playermodel

but it still does the same thing

So to clarify, the player model is the parent, the camera the child. the key down moves/rotates the player model and the camera follows, rotating around the axis of the player model.
'BUT' the camera also rotates around its own axis when collisions occur.


Ross C(Posted 2003) [#8]
right ok. well now you would create a pivot called "cam_pivot" or something

then parent that to the cone, then parent the camera to the cam_pivot. look at it this way. the pivot is the middle of a helicopter blade. the camera is stuck on the end of one of the blades. if you spin the pivot(helicopter blade), the camera will move along. here is some code :D

Graphics3D 800,600,16
SetBuffer BackBuffer()

cam1=CreateCamera()

cone=CreateCone()

cam_pivot=CreatePivot()

light=CreateLight()

;first parent the pivot to the cone
EntityParent cam_pivot,cone

;then parent the camera to the pivot
EntityParent cam1,cam_pivot

; move the camera back from the cone
PositionEntity cam1,0,1,-10

;make some scenary
block=CreateCube()
PositionEntity block,1,0,5

block1=CreateCube()
PositionEntity block1,-2,0,-15

block2=CreateCube()
PositionEntity block2,3,0,-3

;main loop
While Not KeyHit(1)

	;move the cone using arrows keys
	If KeyDown(200) Then MoveEntity cone,0,0,0.1
	If KeyDown(208) Then MoveEntity cone,0,0,-0.1
	If KeyDown(203) Then TurnEntity cone,0,1,0
	If KeyDown(205) Then TurnEntity cone,0,-1,0

	;rotate the camera by rotating the pivot using Z & X
	If KeyDown(44) Then TurnEntity cam_pivot,0,1,0
	If KeyDown(45) Then TurnEntity cam_pivot,0,-1,0
	
	UpdateWorld
	RenderWorld
	Flip
Wend
End



Ruz(Posted 2003) [#9]
So basically , the pivot is just an extra axis to rotate around if we need it?. And in theory we could create more pivots if required in the hierarchy?

thanks for the example. I had something similar set up, but I used the pivot as the parent, then the cone as the 1st child and then the camera at the bottom of the hierarchy.
am I right in thinking that i only need set collisions for the cone/scenery and the camera, not the pivot


Ruz(Posted 2003) [#10]
And also if I set the camera to collide with scenery, the cone moves off in to the distance while my camera stays snagged on the scenery.


(tu) sinu(Posted 2003) [#11]
best thing to do is create 3 pivots, one called CameraMainPivot, position this at the players position but don't parent it to the player but position it there in the loop. Next have a pivot CameraBasePivot and parent this to the CameraMainPivot and position back from where you want the camera to be and finally create a pivot called CameraRotatorPivot and parent this to the CameraBasePivot and position it at the same spot. Parent the camera to the CameraRotatorPivot. For collisions, do those to the CameraBasePivot.

The CameraMainPivot's purpose is to allow you to rotate the camera around the player.
The CamaerBasePivot's purpose is to move the camera up and down.
The CameraRotatorPivot's purpose is to allow the camera to turn left and right or look up and down.
In the long run this way is best cos each pivot has it's own use which doesn't mess up any of the other pivots functions.


Ruz(Posted 2003) [#12]
cool, I will try that today , Thanks a lot.