Question

at the moment i'm working on a 2D plattformer and the work is going very well. But there is one Problem i can't get rid of.

The player can use a dash, which should move the player very fast in the direction he is looking. My problem is, that the player game object instant appears at the target location... like a teleport.

I'm using the AddForce Function to move the game object. On jumping i'm using AddForce as well and there it works really nice, i get a smooth jump movement.

The only different between dash and jump is that on jump i apply force to the y axis and on dash to the x axis. Changing the amount of force doesn't affect the movement only the distance.

Does anyone have an idea what i'm doing wrong?

// Dash
rigidbody2D.AddForce (new Vector2((dashSpeed * direction), 0));
// Jump
rigidbody2D.AddForce (new Vector2(0, jumpForce));

Best, Verdemis :)

EDIT: I can not access my project at the moment, but i will try to show you what i have done.

Note: dashSpeed is a float value, at the moment something like 3500 and direction contains 1 or -1, depending on the direction the player is looking. The Dash code is part of the Update method.

// Dash
if(Input.GetKeyDown(dashKey))
rigidbody2D.AddForce (new Vector2((dashSpeed * direction), 0));
Was it helpful?

Solution 2

Ok i could solved the problem. My problem was that i only did this AddForce only once. The AddForce code was only executed in a single frame. I added a time which i count down to define how long the dash movement gonna be!

OTHER TIPS

What is your direction vector, is it normalized? Since multiplying non-normalized vectors can be rather hazardous. Do you have more of the script to show?

EDIT: You should always do physics things in the FixedUpdate loop(link).

The problem may be that you are using a very big force, I was messing around with some physics today and realized that even a force of 100 almost looks instant. Try making a smaller force number to see if that helps you. I just tested making a smaller number and that does not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top