Gravity on Slopes

Posted By: 82RJZAE

Gravity on Slopes - 08/18/10 23:28

Hi, how might I code proper gravity for a player on slopes? How can I determine what the angle of the slope is in order to increase or decrease the z movement using a c_move instruction? Can anyone provide an example please?
Posted By: 3run

Re: Gravity on Slopes - 08/19/10 06:39

Look at my website in downloads, there is some player movement example with gravity and crawling. That might be useful for u.
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/20/10 20:26

Thanks 3run, I found some of your code useful; however, I did not find any code related to gravity on slopes. I want to be able to make the player slide on steep slopes but I am unsure how I can detect the slope angle in order to determine the z speed to move the player down with. Any suggestions please?
Posted By: Liamissimo

Re: Gravity on Slopes - 08/20/10 20:47

Use c_trace and then the normal extension. It gives you the angle of the traced block
Posted By: EvilSOB

Re: Gravity on Slopes - 08/20/10 21:27

As BARE-BONES code
Code:
c_trace(from, to, USE_POLYGON);
if(trace_hit)  {  angle = acos(hit.nz);  }


where 'angle = 0' is flat ground, and 'angle = 90' is vertical wall.

Hope this helps.

Posted By: painkiller

Re: Gravity on Slopes - 08/20/10 22:01

Originally Posted By: 82RJZAE
Thanks 3run, I found some of your code useful; however, I did not find any code related to gravity on slopes. I want to be able to make the player slide on steep slopes but I am unsure how I can detect the slope angle in order to determine the z speed to move the player down with. Any suggestions please?


with the code from 3run you can slide through slopes without any other change on vertical speed, test it and you'll see. Also in the projects forum I've in the sci-fi shooter posted a demo for movement including also jumping and a test level so you can see it yourself.
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/26/10 02:54

I can use the normal extension to apply a gravity force to the player on slopes but this causes the player to not be able to overstep steps and ledges. Can anyone suggest a solution to this?
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/28/10 18:37

Can anyone help me with applying the gravity on slopes? 3run's nor painkiller's movement codes factor an application of gravity on slopes.
Posted By: painkiller

Re: Gravity on Slopes - 08/28/10 18:58

we don't apply it because it isn't neccesary. but you can make a c_tace on front of the player to the ground and if the heught is bigger than the height of the gravity's c_trace, the you move up the enitity.
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/28/10 19:13

Originally Posted By: painkiller
we don't apply it because it isn't neccesary.

3run's movement code allows the player to run even up the steepest slopes. Wouldn't it be necessary to prevent that?

Originally Posted By: painkiller
but you can make a c_tace on front of the player to the ground and if the heught is bigger than the height of the gravity's c_trace, the you move up the enitity.

The player is not necessarily moving forward up slopes. He might be moving backwards or even strafing left or right.
Posted By: painkiller

Re: Gravity on Slopes - 08/28/10 19:44

you can adjust move_friction to avoid that
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/28/10 21:25

How so? Increasing move_friction still allows the character to be able to scale slopes:

I have created a sample level using the same scripts you uploaded: http://www.mediafire.com/?3tnwx63ydbme38t
Posted By: painkiller

Re: Gravity on Slopes - 08/28/10 23:09

well, that's because in the handle_movement() function, at the end, there is a move_friction=0, delete it of set it to 1 and you will see that the player can't go up stairs.
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/29/10 00:13

The player can't go up the stairs if you hold the movement keys down. If you tap the keys instead, the player can still move up the stairs and scale the walls.
Posted By: painkiller

Re: Gravity on Slopes - 08/29/10 10:32

Then you can do what I said in another post before, make a c_trace in front of the player and substract the first hit.z from the second hit.z and if the difference is bigger than a "x" value, then don't allow the player to move forward
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/30/10 06:06

Wouldn't you still run into the problem where you can't assume the player is moving forward into a slope? The player could be strafing or moving backwards which would make a second c_trace useless unless you could somehow use it on all sides!

I would also still run into my original problem where the player would not be able to overstep stairs.

What I am simply looking for is something like how the gravity is applied to the player in the A5 templates. Here is a sample level I put together using the template which demonstrates what I mean: http://www.mediafire.com/?ftbdvztm5r5waya Can anyone simplify the template code or explain how it is done?
Posted By: 3run

Re: Gravity on Slopes - 08/30/10 07:20

Converted the main movement part in to lite-c, here you go:
Download link
I hope this is what you was looking for. Enjoy.
Posted By: 82RJZAE

Re: Gravity on Slopes - 08/30/10 18:02

Thanks 3run! Is there any reason why when you move up a steep slope or stairs that it pushes you in a direction relative to the object's orientation?

See this example: http://www.mediafire.com/?t2pez9a7ua59b50
© 2023 lite-C Forums