How do i rotate a vector around a normal?

This topic is 4786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, i want to make a (3D) character controller where a character can go up hills just like on flat land, so i have a normal of surface below the character and the new force that would be given to the character as if he was on level land - if i use this force when he is on hill he is pushed into the hill which makes it unable to climb on hills properly, my math skills aren't elite, so i am asking, how could i "transform" or the velocity vector of character by the floor normal?

Share on other sites
You find the axis of rotation by taking the cross-product of the terrain's normal and the object "up" vector -- axis = cross( normal, up ). You find the angle of rotation by computing the arccosine of the dot product of the terrain's normal and the objects "up" vector -- angle = acos( dot( normal, up) ). Apply that to the direction of travel.

Share on other sites
Quote:
 Original post by JohnBoltonYou find the axis of rotation by taking the cross-product of the terrain's normal and the object "up" vector -- axis = cross( normal, up ). You find the angle of rotation by computing the arccosine of the dot product of the terrain's normal and the objects "up" vector -- angle = acos( dot( normal, up) ). Apply that to the direction of travel.

woah, let's say i understood the first 20 words, but then it lost tracking of things to do, and what do you mean with the direction of travel - is this the velocity vector i was talking about?

Share on other sites
Couple of questions. Do you want the character to be aligned with the ground normal, or remain upright when going up hills? (I'd think the latter would be more natural as it's what people tend to do to maintain their balance. Also, John's solution applies to both cases, but it'll be easier to explain how to use it if we know what behavior you want.)

Also, do you already have collision detection working between the character and the terrain, or is that also part of the problem to be solved?

Share on other sites
Quote:
 Original post by jykCouple of questions. Do you want the character to be aligned with the ground normal, or remain upright when going up hills? (I'd think the latter would be more natural as it's what people tend to do to maintain their balance. Also, John's solution applies to both cases, but it'll be easier to explain how to use it if we know what behavior you want.)Also, do you already have collision detection working between the character and the terrain, or is that also part of the problem to be solved?

i'd have the character to remain upright, i use newton physics engine for collision and dynamics, but it is still on me to implement a character controller, it is for this game: http://www.gamedev.net/community/forums/topic.asp?topic_id=355685

if you go with the character uphill you will see you can't do that very easily as you try to push actor into the floor, and similar glitch applies when going downhill - you practically fly because of the lack of contact maintaince with floor.

Share on other sites
So all you want to do is align the movement direction to the terrain surface? This shouldn't be too hard if you have the normal. Assume you have your current acceleration/force vector V from player input. You'll want to remove the component that's in the direction of the surface normal N, and then rescale the vector so that your speed (or acceleration or whatever) stays constant.

V = V - (V dot N)*N
V = normalize(V) * original_force_magnitude

Share on other sites
Thanks Fingers, i materialized the pseudocode into this code, please confirm this is correct:

<code>
dp:= DotProduct(V, N);

V.X:= V.X - dp * N.X;
V.Y:= V.Y - dp * N.Y;
V.Z:= V.Z - dp * N.Z;

V:= Scalevector( normalize(V), original_force_magnitude);
</code>

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633734
• Total Posts
3013587
×