x


Transforming while jumping launches controller into space

So I'm working on a game that transforms the First Person Controller whenever they come into contact with an object. The Controller is transformed 1 unit up on the y axis. While the controller will transform perfectly if it walking and it hits the object, if the character hits the object while jumping then the transform seems to add to the jumping velocity and launches the controller super high in the air. Has anyone else noticed this and/or know of a solution to it?

more ▼

asked Feb 29 '12 at 05:01 PM

L5D7 gravatar image

L5D7
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

The jump with the character controller is performed with a velocity and the function move. When you hit that cube while jumping, the velocity is unchanged, so it keep travelling the distance it's supposed to, plus the +1 unit you gave it. I'm not sure that accuracy (+1 unit) is going well with physic, you might have to choose between them.

more ▼

answered Feb 29 '12 at 05:21 PM

Berenger gravatar image

Berenger
11k 12 19 53

Thank you for replying, is there a way I can disable the jumping mid-script? So that once it collides with the cube while jumping, the jumping stops and the +1 takes over?

Feb 29 '12 at 05:41 PM L5D7

CharacterMotor have a SetVelocity function. call SetVelocity(Vector.zero). Be carefull, SnedMessage("OnExternalVelocity") will throw an error if you don't have the function, as well add SendMessageOptions.DontRequireReceiver to it.

Feb 29 '12 at 06:05 PM Berenger

Thanks for the advice but that didn't quite work. It changes the velocity but the velocity is compiled every update so it doesnt matter what you change it to. I was able to locate where the controller is being launched upwards, it around line 402 in CharacterMotor.js

velocity.y = movement.velocity.y - movement.gravity * Time.deltaTime;

movement.velocity.y is the reference that is the enormous jump (the value was around 40 at it's highest). To fix it I put a limit on the velocity right after this line so that if the velocity is over 6, then limit it to 6 (6 was the value for an average jump).

velocity.y = movement.velocity.y - movement.gravity * Time.deltaTime; if(velocity.y > 6) velocity.y=6;

This works and the Controller now jumps and translates together without high-five-ing the moon. Thank you again for your help.

Feb 29 '12 at 09:39 PM L5D7
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1274
x176
x108
x51

asked: Feb 29 '12 at 05:01 PM

Seen: 628 times

Last Updated: Feb 29 '12 at 09:39 PM