angle adjustment

Posted By: molotov

angle adjustment - 08/19/10 07:39

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.
Posted By: Helghast

Re: angle adjustment - 08/19/10 07:41

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,
Posted By: molotov

Re: angle adjustment - 08/19/10 08:05

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.
Posted By: molotov

Re: angle adjustment - 08/19/10 08:14

Thanks Helghast for your help, I just found the solution in one of the Aum's. Thanks.
Posted By: Helghast

Re: angle adjustment - 08/19/10 08:46

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,
© 2024 lite-C Forums