So I have shifted to avoid using physics forces and velocities and made my own custom code with the help of rb.MovePosition() . The player sticks to the ground on slopes, which is perfectly what I want, except when going uphill. I would want that if the player is fast enough, they should be able to fly off from the uphill slope. What would be the logic behind making that work? Here is a clip of what the movement looks like rn:
#How to let player not stick to ground when going uphill? (2D Platformer)
1 messages · Page 1 of 1 (latest)
define going fast enough, and define fly off
like they keep moving in the direction forever off the cliff? into the sky?
Not forever, I mean imagine a skateboarder racing upwards a slope, they'd definitely catch some air time before coming back down right? But in my game the player sticks most of the time.
Fast enough, well it can be a speed threshold I can set up in the script
Example
why not use the physics engine
Because it doesn't want to stick to the ground. I get the opposite behaviour. Let me share a vid
It applies velocity relative to the player rotation btw
that looks exactly like what you want
Imagine this video but he can't roll down the slope, instead he just flies off midair for a sec until gravity acts and brings him down, that's exactly what's going on in my situation.
be more precise
You're honestly kinda confusing us on what you're trying to do. When do you want the player to stick to the ground and when do you want him to fly or shoot off?
Is the skateboard video an example of what you want, or an example of what you don't want?
It feels like you're telling us one thing, and then turning around and saying the opposite.
Sorry I didn't mean to confuse. I want the skateboard example basically
So it should stick to the ground when the player goes downhill, and fly off when reaching the edge of an uphill.
should it be physically accurate
well if the skateboard example is physically accurate then yes
okay use physics engine
yeah so... If you want totally accurate physics, then you will want to use the physics system. Sticking to the ground is not something real skateboards do. Any thing that looks like it adhesion to the terrain is simply caused by two things: 1, the inertia of the board and rider, and 2, the centripetal force of the concave slope on the board.
How do I control these 2 forces in unity?
If you want the player character to work like a real person on a skateboard, the answer is this: You don’t control them; you let rigidbody physics work that for you.
but i already tried it and it didnt work as intended
reference
I have to ask now: do you understand what these “forces” are?
yes i know generally what they mean
so inertia is mass, centripetal force is mainly due to gravity
Wow! Very much no!
oh
if u really want me to go detail and explain u that i undestand it, inertia is the fact that an object prefers to remain in its current state of motion, and the more mass, the more difficult it is to change that
ok yes that's right.
but i prefer not going in detail and rather help me understand what im doing wrong
the code is a simple addforce, relative to player's transform.right, and using rigidbody's gravity
I was about to say. Could you show us the code? I think I sort of get the idea now, but I still would like a code-block anyway.
