Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 530 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Baklazhan, Hanky27, firatv, wandaluciaia, Mega_Rod
19052 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Walking on surfaces and adjusting angles #291741
09/27/09 17:38
09/27/09 17:38
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
Hi guys,

I'm currently doing a fan-fic of Sonic the Hedgehog. As you probably know, Sonic is able to run enormously FAST and capable of running up walls, ceilings, loopings and so on. I've got the gravity in place, the overall movement is up and running, but I need to get the TILT and ROLL angles right for my model, because its feet are supposed to face the ground at any time, even while running in a looping (so at the highest point of a looping, the model is supposed to be upside-down, when running up a wall, feet, body and head should be aligned in a horizontal manner instead of a vertical and so on).
So, I had a look at the c_trace-command. It modifies the "target" vector and the "normal" vector, the latter giving us the normal of the hit surface (therefore the normal of the surface we are currently walking/running on). The question is: how do I convert the normal vector of the surface the model is currently walking on into tilt and roll angles so that Sonics feet point towards the ground?

Greets and thanks in advance!


Alan

Re: Walking on surfaces and adjusting angles [Re: Alan] #291754
09/27/09 18:28
09/27/09 18:28
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
I think 'vec_to_angle' is what you want.

Re: Walking on surfaces and adjusting angles [Re: DJBMASTER] #291769
09/27/09 19:52
09/27/09 19:52
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
i think c_trace and normal vector + vec_to_angle is what you want.


3333333333
Re: Walking on surfaces and adjusting angles [Re: Quad] #291800
09/28/09 04:01
09/28/09 04:01
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
It seems to be quite a popular problem these days. I just put up a contribution under "Lite-C Contributions" that should help you out.

It's a function that takes an angle and two vectors (one from the world -- using "normal" after c_trace or c_move makes sense -- and one local vector that you want to align with the world one -- using "vector(0, 0, 1)" will make Sonic's feet line-up on the surface underneath him), and modifies the angle so that it lines up.

It doesn't use vec_to_angle.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: Walking on surfaces and adjusting angles [Re: JibbSmart] #291822
09/28/09 11:08
09/28/09 11:08
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
@DJBMASTER&Quadraxas: I already tried to use vec_to_angle in combination with c_trace. The main problem is that "vec_to_angle" outputs *pan* and *tilt* angles. The pan-angle, however, is controlled by the player (left/right cursor keys) and determines the direction Sonic is moving at. What I need is to get tilt and roll correct instead of pan and tilt, see the difference? So getting the right tilt angle is no problem at all, but the roll-angle causes enormous problems.

@JulsMighty: Okay, that sounds just like the function I need. But yet I do not fully understand all parameters. The angle is clear, the first vector (world coordinates) is clear as well, but what about that local vector? What meaning does it have and where do I get it from? Or is it just *always* (0,0,1) if I want Sonic's feet to face the surface underneath them?

Re: Walking on surfaces and adjusting angles [Re: Alan] #291914
09/28/09 21:52
09/28/09 21:52
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
It allows the function to be more general:

It will *always* be (0, 0, 1) if you want Sonic's feet to face the surface underneath them (that is, the function will line up Sonic's "up" with the surface normal). If you use (1, 0, 0), Sonic's back will line up with the surface you c_trace, since it'll line up Sonic's local x-axis with the surface normal (this would be similar to "vec_to_angle", except the roll won't necessarily be zero, since only the smallest rotation possible is done to line the angle up).

Don't forget to rotate Sonic's pan relative to his current orientation (using ang_rotate or c_rotate(..., USE_AXIS)) instead of just adding or subtracting to his pan.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: Walking on surfaces and adjusting angles [Re: JibbSmart] #291917
09/28/09 22:03
09/28/09 22:03
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
@JulzMighty: Oh, I see, now I get the hang in it! I will definitly try your function tomorrow, sounds really great, logical and easy to use. Thanks for your explanation wink

Greets and thanx


Alan

Re: Walking on surfaces and adjusting angles [Re: Alan] #294019
10/15/09 15:46
10/15/09 15:46
Joined: Jul 2008
Posts: 128
Ukraine
BastovBros Offline
Member
BastovBros  Offline
Member

Joined: Jul 2008
Posts: 128
Ukraine
Well, I have a similar problem and I did not actually get it. I have a vehicle and a terrain with hills and slopes. I want to make this vehicle always stay perpendicular to the surface. I tried to use c_trace and vec_to_angle and normal but the vehicle looks with its x axis to the surface instead of z axis. So how can I make the vehicle be always perpendicular to the surface at an angle or slope of the terrain?
Thanks.


a generator of dull questions smile
Re: Walking on surfaces and adjusting angles [Re: BastovBros] #294336
10/18/09 14:41
10/18/09 14:41
Joined: May 2006
Posts: 90
England
TigerTao Offline
Junior Member
TigerTao  Offline
Junior Member

Joined: May 2006
Posts: 90
England
Hi not sure if this helps as Im getting back into GS after a hiatus of a year so I cannot guarantee it works now. This is some old code not made by me that works after a trace. Basically this can be converted to contain changes to the roll as it only currently converts the tilt of the surface to the player. The my.tilt += 0.1....is there to smoothly change the the tilt angle of the player.

Hope this helps...


temp.tilt = 0;
temp.roll = 0;
temp.pan = -my.pan;
vec_rotate(normal, temp);
temp.tilt = -asin(normal.x);
my.tilt += 0.1 * ang(temp.tilt - my.tilt); // play with 0.1
my.roll = 0;

Re: Walking on surfaces and adjusting angles [Re: TigerTao] #294738
10/20/09 21:25
10/20/09 21:25
Joined: Jul 2008
Posts: 128
Ukraine
BastovBros Offline
Member
BastovBros  Offline
Member

Joined: Jul 2008
Posts: 128
Ukraine
Thanks Tiger Tao, I added this line "my.roll += 0.1* ang(temp.z - my.roll); " to the code and now the angles are adjusted as they should. Though I do not think that I will use it now.... I am "playing" with my.tilt values but still can't make the movement be smooth enough. I think this code is perfect for human movements or some other objects, but not for vehicles. So, I will definitely use it, but for other purposes. The bad thing is that I do not yet understand the math behind this script, I need time to figure it out. Thank you anyways.


a generator of dull questions smile

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1