swimming

Blitz3D Forums/Blitz3D Beginners Area/swimming

chrisnorris007(Posted 2009) [#1]
whats the most efficient way of handling swimming...

i want to ... change my character to his swimming animation and make the controls change so that a is still forward z is back still....but i can turn my dude up and down left and right and swim...


Drak(Posted 2009) [#2]
Simply switch to the swimming animation and continue to move the player forward if the a key is hit, or z key, or whatever.

Maybe something like this:
If swimming = 1
	Animate player,1,1,treadsequence,10
	
	If KeyDown(17) = 1
		Animate player,1,1,swimsequence,10	;this overrides the previous animate call if the player is moving
		MoveEntity player, 0,0,1
	EndIf
EndIf  


You will of course, need to do the "If" statements for all the movement keys. This is just a simple example.


stayne(Posted 2009) [#3]
Swimming is tricky as you have to prevent the player from moving up past the water mesh. Once under water, cancel gravity on the player until he reaches EntityY of your water mesh. Start with something like...

If EntityY(player) < EntityY(water) Then gravity = 0 Else gravity = -1


jfk EO-11110(Posted 2009) [#4]
In my project the player can look down, this will allow him to dive under water. Only when he is looking up, he will stay on the surface on the water, and be able to swim.

You may also add a further pivot to the head of the player, this way you can control the gravity in water: when the head if over the water and the rest under water then you may set gravity to zero, for swimming.


chrisnorris007(Posted 2009) [#5]
jfk, can you show me in code what you are talking about? i am intrigued about the concept your talking about.


jfk EO-11110(Posted 2009) [#6]
Well, maybe it's better for you when you write it by your own. It's not a big deal.
Just detect the position of the payer. You may use a box for the water, this simplyfies checking if (and how far) the player is within the water.

If the conditions fit for swimming, activate swim mode. The players motion should then be smoothed a lot, especially start and stop moving. You need a speed variable for that. When the player start swimming, the speed variable slowly increases up to a certain speed, when he stops pressing "W" (or whatever key) then the speed variable will decrease slowly until it reaches zero.

The player will then moveentity by the speed variable each frame, so he starts and stops smoothly, like in water. Everything else should work automaticly by collsion vs ground (eg. getting out of the pool).

In my case I had to add a further mode, the scuba dive mode. Testing the EntityPitch of the head tells me if the player (FPS) is looking down. If so, I add a little bit of gravity, so he may sink down slowly. Additionally I switch to an alternative movement system that is best described as Superman - freeflight mode, so you can move in every wanted direction under water (where the standard walking as well as swimming animation usualy pushes the player only forward, but never upward)


Zethrax(Posted 2009) [#7]
The systems linked below may be useful in detecting if an entity has entered or exited a waterblock:-

http://www.blitzbasic.com/codearcs/codearcs.php?code=1901
http://www.blitzbasic.com/codearcs/codearcs.php?code=1920