[SOLVED] 2DController tutorial script translated to C#

So I’ve tried to translate some of the 2D tutorial scripts to C#. I thought it was fairly easy until I ran the game and my character just flew away… :slight_smile: I’ve been trying to find the problem but no success. It can be something I have mistranslated or misspelled.

My #1 culprit is this line:

// Calculate actual motion
var currentMovementOffset = movement.direction * movement.speed + Vector3 (0, movement.verticalSpeed, 0) + movement.inAirVelocity;

Best I can do is:

// Calculate actual motion
Vector3 currentMovementOffset = movement.direction * (movement.speed + movement.verticalSpeed) + movement.inAirVelocity;

I just can’t figure it out. :frowning:

Here is the whole script, if anyone could be so kind and help me out or at least point me into the right direction, I would be ever so grateful!

279404–10019–$player13_205.cs (12.2 KB)

Hi, welcome to the forum!

If the player is flying into the air, it probably means you were expecting to have gravity but it is being applied in the wrong direction. See if putting a minus sign before movement.verticalSpeed gives the right result.

Thanks for the welcome! :slight_smile:

I didn’t explain it well enough, the character flies in the Z-axis (minus), towards the camera.

It must be that piece of code that is the problem…the character stays put if I don’t use that code. Maybe that’s why the jumping isn’t working too!

Vector3 vertical = new Vector3(0, verticalSpeed, 0);
        Vector3 currentMovementOffset = moveDirection * speed + vertical + inAirVelocity;

Ugh, took me long enough to figure it out! :sweat_smile:

Working on making the jump look better now…