Skip to main content
gamedev.net
🔒 Locked

Vector problem

Started by gorgorath Jan 16, 2003 at 12:05 PM 0 replies 650+ views
Original Post
gorgorath
gorgorath
hey All, I''ve got a little problem where some Vector math is involved I have a simple 3d game where you can shoot monsters, pick up ammo etc. etc.There is some collision detection currently involved but only on a real basic level. Like assuming the player is always on the same height, no obstacles and such and whenever the player hits a wall he''s stuck in it( no sliding ) cause all that the collisionDetection does is giving back a "bool", so when false no further movement is allowed. But what I want is to add gravity and sliding along walls to the game. So I have this worked out, in the hope it works: The whole time there''s a (constant) gravity: x , y(gravity), z Vector gravity( 0.57, -0.57 , 0.57 ); this is constantly pulling at the player. We have a Vertex where the player is at the moment: position( posX, posY, posZ ); We have a Vector where the player is currently Moving at: moveDir( moveX, moveY, MoveZ ) But my question is can I multiply the moveDir and the Gravity vector? That results in a new vector, let''s say the "force" Vector? And normalize that and calculate a new position for the player? In shourt should I first calculate the gravity and after that calculate the direction movement or can I easily combine it? I hope the problem is understandable cheers, Paul
Cosmic Keys to my Creations & Times
ga
ga
quote:

But my question is can I multiply the moveDir and the Gravity vector? That results in a new vector, let''s say the "force" Vector? And normalize that and calculate a new position for the player?



this would lead to nothing, where do you get this from?

there is the current position and the current velocity of the player. each time frame, add the velocity vector to the position vector.

but there''s also acceleration, the change of velocity. acceleration is caused by forces, a = F/m (a = acceleration, F = force, m = mass; a and F are vectors whereas m is a scalar).
the gravitational force is proportional to the mass(Fg = m*g), so you can treat it as acceleration, the acceleration vector for gravity is (0, -g, 0) (if y is your vertical direction).
btw, g is a constant, on earth g = 9.81 m/s^2


acceleration is also caused by player movement (basically, you can forget the distinction between accelerations and forces as long as your mass is constant). you have to try the acceleration which will fit for your game (and while flying in air the player movement acceleration should be lower of course).

to limit the velocity a player can reach, you have to take friction into account. it''s an aceleration pointing to the opposite direction of the velocity, make it''s absolute value either constant or proportional to the velocity.

add up all accleration vector and add the acceleration vector to the velocity vector each frame, but don''t forget that if the player is currently touching a colission object the velocity vector may not move the player into that object.
Visit our homepage: www.rarebyte.de.stGA

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.