Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
angle adjustment #338561
08/19/10 07:39
08/19/10 07:39
Joined: Apr 2006
Posts: 329
M
molotov Offline OP
Senior Member
molotov  Offline OP
Senior Member
M

Joined: Apr 2006
Posts: 329
Hey, I've a block which I move using c-move. When the block aproaches a terrain, I want it to adjust it's tilt and roll according to the slope angle. Can someone show me some code that does that nicely. Thanks.

Re: angle adjustment [Re: molotov] #338562
08/19/10 07:41
08/19/10 07:41
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
I have this in one of my old codes:
Code:
// code lend from JulzMighty : http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=291799#Post291799
void alignToVec(ANGLE* entAng, VECTOR* vec, VECTOR* axis, var factor) {
	vec_rotate(axis, entAng);
	vec_normalize(axis, 1);
	vec_normalize(vec, 1);
	VECTOR rotAxis;
	vec_cross(rotAxis, vec, axis);
	var angle = -acos((float)vec_dot(axis, vec)) * factor * vec_length(rotAxis);
	ANGLE rotAngle;
	ang_for_axis(rotAngle, rotAxis, angle);
	ang_add(entAng, rotAngle);
}



Look at the comment for credits and link to topic.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: angle adjustment [Re: Helghast] #338564
08/19/10 08:05
08/19/10 08:05
Joined: Apr 2006
Posts: 329
M
molotov Offline OP
Senior Member
molotov  Offline OP
Senior Member
M

Joined: Apr 2006
Posts: 329
The code looks ok, but should I not use somekind of trace from the box downwards to detect the slope/surface angle? And how do I aply the trace to this code? Thanks.

Re: angle adjustment [Re: molotov] #338565
08/19/10 08:14
08/19/10 08:14
Joined: Apr 2006
Posts: 329
M
molotov Offline OP
Senior Member
molotov  Offline OP
Senior Member
M

Joined: Apr 2006
Posts: 329
Thanks Helghast for your help, I just found the solution in one of the Aum's. Thanks.

Re: angle adjustment [Re: molotov] #338567
08/19/10 08:46
08/19/10 08:46
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
You are right indeed, I have it applied right after my gravity trace:
Code:
// do a trace to get the z position below the entity
tracePos = c_trace(my.x, vector(my.x, my.y, my.z - 500), IGNORE_FLAG2 | IGNORE_ME | IGNORE_PASSABLE | IGNORE_PUSH);
alignToVec(my.pan, normal, vector(0,0,1), 15); // awesome for scaling walls, bit useless in a beat em up
// set the position of the entity smoothly to the trace target



Even though you already found it out, I'm posting this for others to learn from as well laugh
The only thing that you could do to improve my code, is use math to do a trace depending on the characters rotation, rather then always straight down...

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/

Moderated by  adoado, checkbutton, mk_1, Perro 

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