Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make character levitate? (while allowing movement on X/Z planes)

Asked by 2 years ago
Edited 2 years ago

Hi, I'm new to this website, so sorry if I am unconsciously breaking any rules or anything. I am trying to create a script that while a certain button is held, the player is able to essentially levitate in midair. Additionally, the player would be able to move around on the X and Z axes normally (WASD), while not being able to move on the Y axis (up/down).

I have tried using a VectorForce to counteract gravity (with force = character mass * gravity), but the problem is that this only stops acceleration and doesn't account for the initial velocity. For example, if the character is falling at 5 studs/second and the button is suddenly held, the character would continue to fall at a constant 5 studs/second. Another problem is that bumping into an object would add the reaction force to the player, potentially moving the character up or down on the Y-axis. I want the character to be locked in the Y-coordinate.

I have also tried using an AlignPosition (with OneAttachment mode) to keep the character in the air. To do so, I set the target position to the character's position as soon as the button is pressed. However, this negates the ability to move around the X and Z planes, because the force is constantly keeping the character in place at the original location. I could use a heartbeat function, to constantly move the target position above the character, but turning in a different direction could cause a loss of speed. I want the character to be able to move around the X/Z planes.

I have also tried using a LinearVelocity and setting the force to (0,0,0), but that negates movement on the X and Z planes. If I could use a LinearVelocity to only affect the Y-coordinate, that would solve my problem entirely, but as far as I know, that can't be done normally.

I've been stuck on this problem for a few weeks now, any help or thoughts are greatly appreciated!

Answer this question