6
$\begingroup$

I have a character with a very simple motion control: when I press W the character moves forward, with S they it goes backwards and so on. The problem is that unlike what is possible in the real world, releasing the movement button halts the character instantly; the same happens in mid air - if you were going forward and, mid air pressed the button to go backwards, you will, which us impossible IRL and, thus, not what I want. How can I make it so the character has to first slow down, before being able to switch direction (for large-ish turn angles)?

The problem with the current suggestions is that it only partly fixes my problem, in that if I try to switch direction mid-air, it starts to move backwards with the same velocity it had when moving forward (i.e. the speed suddenly becomes negative), which is not what I want.

$\endgroup$
  • 1
    $\begingroup$ use linear velocity instead of translation. $\endgroup$ – Scalia May 17 '15 at 18:38
  • $\begingroup$ @Radish of the Opera That would not work. It creates half of what I need and half of what I want to avoid. $\endgroup$ – blackhole May 19 '15 at 16:09
  • 2
    $\begingroup$ "I know less than half of you half as well as I should like, and I like less than half of you half as well as you deserve." $\endgroup$ – Scalia May 19 '15 at 16:53
  • 2
    $\begingroup$ you confuse me. $\endgroup$ – Scalia May 19 '15 at 16:53
  • 1
    $\begingroup$ then turn up friction. for #2 see blender.stackexchange.com/questions/21137/… $\endgroup$ – Scalia May 20 '15 at 3:40
4
+25
$\begingroup$

All of the answers here so far do not quite fix your problem. it is actually quite easy to fix. Radish Has the right idea (using linear velocity set to Add). This answer also expands (and says more clearly) what StealthyRobot said in his answer. (Although the numbers which he gave there do not work as expected)

First you need to use linear velocity with the settings local and add enabled. (I assume you already have this)

enter image description here

Now we can fix the overshoot problem. to do this increase the damping on the Translation for your character.

enter image description here

If you are using Torque to steer, also set Rotation dampening.

It also might be useful to view this question

Realistic Jet Flight

You can see it working here

enter image description here

If you had trouble following that, (hopefully you did not) or if you just want to see it working, feel free to take apart/play with the blend file.

$\endgroup$
  • $\begingroup$ I was about to tell you everything basically was flawless until I had noticed the following: if you fall and are facing upwards, you can accelerate and start floating and gain speed... $\endgroup$ – blackhole Jun 4 '15 at 0:10
  • $\begingroup$ There are several things you can do to fix this, you can add a collision sensor to make sure that the character is on the ground to be able to drive and steer, or you could make it only dynamic so it can never point upwards. You could also limit the rotation on the rigid body so it can only rotate along the Z axis. $\endgroup$ – X-27 the fluffy unicorn Jun 4 '15 at 0:25
  • 2
    $\begingroup$ I think you've earned it! :) $\endgroup$ – blackhole Jun 4 '15 at 0:26
  • $\begingroup$ Just do this to your character i.stack.imgur.com/xOlUZ.png (Don't forget to add that same property to the ground) $\endgroup$ – X-27 the fluffy unicorn Jun 4 '15 at 0:29
  • $\begingroup$ I am having trouble: my character falls extremely slow with the translation that high. How can I fix this? He also cannot pass a certain point in speed when falling down. $\endgroup$ – blackhole Jun 4 '15 at 22:54
3
$\begingroup$

There are two things I can suggest at this point.

Set the linear velocity mode to "Add"

I know you think I'm super ignorant or something, but for whatever reason I still don't quite see the problem. This quote:

in that if I try to switch direction mid-air, it starts to move backwards with the same velocity it had when moving forward

suggests that the new force is dispersing the other one too quickly (instantaneously?). If this is the case, turning the linear velocity mode to Add might help. This causes the new force to be slowly added to the old one. still experimenting with it, but it seems like you may need to enable "True-Level-Triggering" on your sensor.

You can enable Add with the little "A" next to linear velocity.

enter image description here

Turn up the damping frames

This is another way to slow down the effects of the motion when it is pressed, but unlike add, it applies to even a stationary object.

For example with damping frames, if my cube is still, and I hit "w" triggering my actuator, the cube takes the required frames to build up it's velocity.

If I had used Add instead, 0+1 still equals 1, so the build up isn't like a snail. use add if you can.

You can enable damping frames by typing the number of frames in the damping frames box at the bottom of the logic brick.

enter image description here

$\endgroup$
1
$\begingroup$

You might need to play with the translation movement dampening. A higher value will make you stop and start more suddenly and a lower value will make the object take longer to change its velocity. For example, lets take a standard sized cube with default friction on a plane with default friction. The cube is dynamic and the mass is 1. I prefer more precise movement so I set the movement Dampening between 0.990 to 0.999. I set the dynamic motion to around 20 and it gets around really nicely. Because it has dynamic physics it should slowly float down when in the air.

$\endgroup$
  • $\begingroup$ Didn't work as I have asked. $\endgroup$ – blackhole Jun 1 '15 at 19:39
  • 3
    $\begingroup$ @blackhole you need to specify why it doesn't work rather than generically saying "it doesn't work" $\endgroup$ – Scalia Jun 3 '15 at 15:02
  • $\begingroup$ Read what I've added to clarify what I need. $\endgroup$ – blackhole Jun 3 '15 at 19:57
1
$\begingroup$

Image

Use linear velocity to make this as suggested above. With translation it just teleports. In the image shown you can move towards the x-axis with w. When you stop pressing it, the motion stops. Create 3 more sensors for A/S/D for the different axis and also place them in the script in the same way as "w", as sensors, and copy paste the last 2 lines 3 times for each one of the new sensors and it will work.

Edit: I found some time. This works for all the sensors. No need to have them all in script. blend file

New edit: Ok, I did it with forces and change of states. Here is the new blend file,check it out. If you press space you go to jump state where you have that motion you wanted. But while on the ground you stop instantly when you leave the w,s,a,d.

$\endgroup$
  • $\begingroup$ It does not do diagonal movement. Let me know if you want it and I 'll change it when I get back. $\endgroup$ – Lev Jun 3 '15 at 11:19
  • $\begingroup$ Read what I've added to clarify what I need. $\endgroup$ – blackhole Jun 3 '15 at 19:57
  • $\begingroup$ Changed it accordingly. Check it out. $\endgroup$ – Lev Jun 3 '15 at 21:17
0
$\begingroup$

Actually, that's completely natural. It already has a linear velocity x, so it just goes not x when you hit the next key.

It seems to me that you are trying to emulate the movement of something like a skydiver. Here's an idea that you could try: try making a 'bounding box' that the player can fit inside of that will only collide with the player, make it invisible, and have the WSAD keys affect the bounding box instead. This way, the player's velocity is always zero until bumped by the edge of the box, in which case the player will slide when you release or hit the next key. (You might want to place a parented block underneath it, parented to the bounding box. The block will fall the same rate as the box, and because it isn't the object coded with automatic movement, the player cube will slide on it.) Or at least, that's my theory. It kinda worked the other way around, except this bounding box had to control an independent player while it moved slowly.

Oh, and could you post the blend file so we can take a gander at it please? Thanks, Nefer007

$\endgroup$
  • $\begingroup$ Read what I've added to clarify what I need. $\endgroup$ – blackhole Jun 3 '15 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.