- Home /
Problem is not reproducible or outdated
Skateboarder behaving incorrectly on half-pipe
I'm currently creating a skateboarding game and have hit a bit of a problem with half-pipes. At the moment my character simply moves at a constant forward velocity and adjusts it's orientation based on a downwards raycast (to hug the terrain).
The problem arises when my character goes up a half-pipe. What I want to happen, ala Tony Hawks, is that the character simply continues in it's current motion straight upwards and lands back down on the halfpipe. However, my character is retaining some forward momentum and travels up and over the pipe instead.
My initial solution was to place a trigger at the top op the pipe that adjusts the characters local orientation so they are perpendicular to the imaginary wall of the halfpipe. Here's the code (angleX is set to 270)
Vector3 newLocalAngle = new Vector3(angleX, coll.gameObject.transform.localRotation.eulerAngles.y, coll.gameObject.transform.localRotation.eulerAngles.z);
Vector3 oldLocalAngle = coll.gameObject.transform.localRotation.eulerAngles;
coll.gameObject.transform.localRotation = Quaternion.Euler(newLocalAngle);
I then get rid of any local y velocity on the character, to remove any motion forwards or backwards.
Vector3 newVel = coll.gameObject.transform.InverseTransformDirection(coll.gameObject.GetComponent<Rigidbody>().velocity);
newVel.y = 0;
coll.gameObject.GetComponent<Rigidbody>().velocity = coll.gameObject.transform.TransformDirection(newVel);
This unfortunately is snapping the player to face straight up in the world y direction, stopping any sideways motion (relative to the halfpipe).
Can anyone suggest a fix for this code, or a better way to approach the problem?
Answer by KlausJoensuu · Aug 29, 2015 at 04:57 PM
I'm not sure what you are talking about but i would check the physics settings. Edit -> Project settings -> Physics. You can always just create you're own physics system for scratch too if it is needed. If i was to build a game like that i would start by making a custom physics manager where i can detect if in "Half-pipe". Hope that will help in someway...
Follow this Question
Related Questions
Follow a curve using physics or transform manipulation 2 Answers
How to get rotation relative to the ground normal? 0 Answers
Turning a rigidbody that's in motion 2 Answers
How do I determine which Euler Axis of an object will change when the object is rotated? 1 Answer
Game Object rotation sometimes doesn't match defined quaternion 0 Answers