Camera Switch

Blitz3D Forums/Blitz3D Programming/Camera Switch

wizzlefish(Posted 2005) [#1]
I have two modes in my game: walk mode, and drive mode. They are represented by the variable "cam_mode." If "cam_mode" equals 1, then it is walk mode, where the player can walk around the level. If "cam_mode" equals 2, then it is drive mode, where the player can drive around in a vehicle. I can't really figure out how to switch both of these.

This is the code for "drive mode:"
	If cam_mode = 2
	EntityParent camera, car\entity
	PositionEntity camera, EntityX(car\entity), EntityY(car\entity)+30, EntityZ(car\entity)-10
	RotateEntity camera, EntityPitch(car\entity)+45, EntityYaw(car\entity), EntityPitch(car\entity)
	If KeyDown(17)
		MoveEntity car\entity, 0, 0, 3
	EndIf
	
	If KeyDown(31)
		MoveEntity car\entity, 0, 0, -3
	EndIf
	
	If KeyDown(30)
		TurnEntity car\entity, 0, 1, 0
	EndIf
	
	If KeyDown(32)
		TurnEntity car\entity, 0, -1, 0
	EndIf
	If KeyHit(57)
		cam_mode = 1
	EndIf
	EndIf


You can see that W, S, A, and D, control the car, and the camera is parented to the car. First of all, how would I make it so I wouldn't have to make the EntityParent, PositionEntity, and RotateEntity functions? While the game is running in walk mode, the camera is not parented to the car. In drive mode, it is. I just haven't got it figured out.

All I want to do is make it so if the camera is a certain distance from the car (car\entity), and the spacebar is pressed. And if the spacebar is pressed while in drive mode, then the player is transported right next to the car.

How would I achieve this?


wizzlefish(Posted 2005) [#2]
What? Did I just not explain it clearly enough?


DJWoodgate(Posted 2005) [#3]
EntityParent camera, car\entity
PositonEntity camera,0,30,-10
RotateEntity camera, 45,0,0

Make sure the car is not entityscaled or the camera will be as well.

Alternatively.

Tformpoint 0,30,-10,car\entity,0
PositionEntity camera,tformedx(),tformedy(),tformedz()
pointenttiy camera,car/entity ; or use aligntovector.

Alternatively, and for a bit more variety use something like
http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=798
There are others.


wizzlefish(Posted 2005) [#4]
No, I need them to switch. I have no problem with their views, I just need them to be able to switch from walk mode to drive mode. I can't figure out how to do this without running those tests every frame. And using EntityParent and PositionEntity, etc. EVERY FRAME could be very slow.


DJWoodgate(Posted 2005) [#5]
Time it and see how long it takes.


wizzlefish(Posted 2005) [#6]
OK...then....nevermind :)

So, how would I accompluish this switch?


Ross C(Posted 2005) [#7]
I don't get what your trying to do... Could you explain a bit more?


wizzlefish(Posted 2005) [#8]
Ok, you're in "walk mode" and you are walking around the terrain. Then, while you're colliding with the jeep, and you press space, you switch to "drive mode," where the camera is behind the jeep, in 3rd person view. Then, while you're in the jeep, if you press space, you appear right by the jeep. I just can't figure it out!


WolRon(Posted 2005) [#9]
And using EntityParent and PositionEntity, etc. EVERY FRAME could be very slow.

I may not understand you, but I don't see why you need to perform those checks every frame. Just perform them the first time you hit spacebar, like this:
If KeyHit(57) and cam_mode = 1
	cam_mode = 2
	EntityParent camera, car\entity
	PositionEntity camera, EntityX(car\entity), EntityY(car\entity)+30, EntityZ(car\entity)-10
	RotateEntity camera, EntityPitch(car\entity)+45, EntityYaw(car\entity), EntityPitch(car\entity)
EndIf

And then take these lines:
	EntityParent camera, car\entity
	PositionEntity camera, EntityX(car\entity), EntityY(car\entity)+30, EntityZ(car\entity)-10
	RotateEntity camera, EntityPitch(car\entity)+45, EntityYaw(car\entity), EntityPitch(car\entity)
out of the bit of code you posted at the top of this thread.


wizzlefish(Posted 2005) [#10]
You just saved me hours of thinking.....


wizzlefish(Posted 2005) [#11]
OK, well, I got it figured out. Although I didn't do it. But Wolron, you helped. Alot.