1991mirec
Member
|
under water - swiming
Hi
i know that there are some articles how to dectect if character is under water and so on but my question is how can i make it work so character would swim under watter up or down and forward.
i made it to work with up and down like this
Code:
if(Game::World.waterUnder(pos))
if(Kb.b(KB_T) && !Kb.b(KB_W) && !Ms.b(0) && !Ms.b(1))
ctrl.actor.vel(Vec(0, 1.5, 0)); // to swim up
if(Kb.b(KB_G) && !Kb.b(KB_W) && !Ms.b(0) && !Ms.b(1))
ctrl.actor.vel(Vec(0, -1.5, 0)); // to swim down
if(!Kb.b(KB_W) && !Kb.b(KB_A) && !Kb.b(KB_S) && !Kb.b(KB_D)&& !Ms.b(1) && !Ms.b(0) && !Kb.b(KB_T) && !Kb.b(KB_G))
ctrl.actor.vel(Vec(0, 0, 0)); //to stay on the same spot
Physics.gravity(Vec(0, -5, 0)); // to sink slowly
like this it works up and down and he is sinking slowly as i wanted to but when i press forward button he sank down like this very fast and he will be swiming on the bottom of the lake.
so my question is how can i make it so my character would swim up dawn and forward at the same time. and i don t want to apply flying cause it messes up my animation.
thank you in advance.. mirec
|
|
11-07-2013 09:01 PM |
|
Rubeus
Member
|
RE: under water - swiming
if(Kb.b(KB_T)
ctrl.actor.addVel(Vec(0, 1.5, 0));
if(Kb.b(KB_G)
ctrl.actor.addVel(Vec(0,-1.5, 0));
etc....
Using .vel overwrites the value entirely, while addVel just add to what's there. Simpler, you could use:
Code:
Vec velocity(0);
velocity.x += Kb.b( KB_D ) - Kb.b( KB_A );
velocity.y += Kb.b( KB_T ) - Kb.b( KB_G );
velocity.z += Kb.b( KB_W ) - Kb.b( KB_S );
velocity.normalize( );
velocity.y += -5; // pretend gravity. Remove if you want to be neutrally bouyant
velocity.mul(ctrl.actor.matrix().orn());
ctrl.actor.addVel(velocity * speed_inwater);
Set the ctrl.actor.gravity(false); when entering water, and true when exiting. This way, the gravity change won't affect every object you have.
|
|
11-07-2013 09:38 PM |
|
1991mirec
Member
|
RE: under water - swiming
thank you rebus
but this way if i move forward it works one way just fine but if i turn oposite way i barely move....
|
|
11-08-2013 12:19 PM |
|
Rubeus
Member
|
RE: under water - swiming
It sounds like you then have forces being added to the object somewhere else. This code is a slightly modified version of the code that I use for movement in my project, and is confirmed working.
|
|
11-08-2013 02:46 PM |
|
1991mirec
Member
|
RE: under water - swiming
i made it to work... thank you anyway.
|
|
11-09-2013 06:30 PM |
|