- Home /
Mimic Gravity Movement Via Setting Velocity
Currently, I'm trying to break down a bigger problem into smaller managable bits. I want to make a game where you can walk on the wall and ceiling however I'm having trouble trying to get the gravity to move in the x and z axis. Currently, I'm setting the velocity directly because Add Force resulted in movement that was very slippery and I want the movement in my game to be snappy and responsive.
Naturally, changing the gravity direction alone doesn't make much of a difference as the velocity is been overwritten straight away so I need to apply another force to mimic the gravity for the X and Z axis. That said, what do I need to do? Currently, gravity on Y axis is being handled by the Y velocity which is the only velocity vector that is not being overwritten however it will eventually be used for new movement vectors so I will need to replace it later however one step at a time.
Here's a stripped movement script featuring the basic functionality.
private void MovementCalc()
{
//Original Y Velocity is preserved and added to the movement variable.
//Up Axis is meant to be the act as the gravity direction. Was formely Vector3.up
CurrentYVel = (UpAxis * rb.velocity.y);
//directionIntentY + X are the camera directions. zSaved & xSaved are input axis directions.
//additional Force is used to add additional forces for jump pads, being launched, etc.
MovementVector = (((directionIntentY * zSaved) + (directionIntentX * xSaved)) * TotalSpeed) + AdditionalForce + CurrentYVel;
//If not on slope, just set velocity directly
rb.velocity = MovementVector;
}
Your answer
Follow this Question
Related Questions
Gravity doesn't work 2 Answers
G Force Acceleration 0 Answers
Player movement controls too slow 1 Answer
Input.GetAxis doesn't seem to move me in the direction I am facing 2 Answers
Rigidbody.velocity and Time.deltaTime 3 Answers