Skip to main content
GameDev.net gamedev.net
🔒 Locked

movment

Started by okouya Apr 16, 2002 at 5:05 PM 4 replies 450+ views
Original Post
okouya
okouya
can you explain more please because i was talking about : how do you make the displacement? how do you jump??????? you on vk_ donw case up:.................... left:................ .............. and more...............; if you can please i''m gonna show you what i do for my camera movment: unit camera; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, MMSystem, OpenGL, GLut,gl,glu,collision1; type Tcamera = class position:Tvector; velocity:Tvector; view:Tvector; upvector:Tvector; rayon:glfloat; constructor Create; procedure positioncamera(posx:glfloat;posy:glfloat;posz:glfloat;viewx:glfloat; viewy:glfloat;viewz:glfloat;upx:glfloat;upy:glfloat;upz:glfloat); procedure mov(speed:glfloat); procedure rotate(dir:glfloat); procedure rotatearound(joueur:Tvector;dir:glfloat); end; implementation constructor Tcamera.Create; begin inherited Create; with position do begin x:=0; y:=0; z:=0; end; with view do begin x:=0; y:=1.0; z:=0.5; end; with upvector do begin x:=0; y:=1; z:=0; end; rayon:=0.0; end; procedure Tcamera.positioncamera(posx:glfloat;posy:glfloat;posz:glfloat;viewx:glfloat; viewy:glfloat;viewz:glfloat;upx:glfloat;upy:glfloat;upz:glfloat); begin with position do begin x:=posx; y:=posy; z:=posz; end; with view do begin x:=viewx; y:=viewy; z:=viewz; end; with upvector do begin x:=upx; y:=upy; z:=upz; end; end; procedure Tcamera.mov(speed:glfloat); var aux:tvector; begin // on obtient d''abord le vecteur indiquant la direction // en laquelle nous regardons with aux do begin x:=view.x-position.x; y:=view.y-position.y; z:=view.z-position.z; end; position.x:=position.x+aux.x*speed; position.z:=position.z+aux.z*speed; view.x:=view.x+aux.x*speed; view.z:=view.z+aux.z*speed; end; procedure Tcamera.rotate(dir:glfloat); var aux:Tvector; begin with aux do begin x:=view.x-position.x; y:=view.y-position.y; z:=view.z-position.z; end; view.z:=(position.z+sin(dir)*aux.x+cos(dir)*aux.z); view.x:=(position.x+cos(dir)*aux.x-sin(dir)*aux.z); end; procedure Tcamera.rotatearound(joueur:Tvector;dir:glfloat); var aux:Tvector; begin with aux do begin x:=position.x-joueur.x; y:=position.y-joueur.y; z:=position.z-joueur.z; end; position.z:=(joueur.z+sin(dir)*aux.x+cos(dir)*aux.z); position.x:=(joueur.x+cos(dir)*aux.x-sin(dir)*aux.z); end; the things is that i don''t hav any velocity vector or acceleration in my class as you can see so can you complete me or arrange this to implemente all thiss with velocity or what you want................ end. love and peace
love and peace
coelurus
coelurus
Somehow, I hate looking in others sourcecodes... Btw, it''s Pascal, so I''ll give it a shot.

First thought:
This is the camera class, right? It should only handle the camera, not the player. Therefore, you should make another class for the physics of the player (this camera class can be used for spectating etc). Write all new stuff into the new player-physics class.

About the displacement:
I see that you have some movement code for moving by some parameter "speed". Doesn''t this work, or what''s the problem with moving?

About jumping then:
Declare a variable, called "jump" or something nice. When the user presses the jump key, set the jump variable to the speed of the jump upwards. Decrement this variable and each time, you move the player up by "jump" units. When jump reaches 0, don''t decrement it any more, and wait until the player presses the jump key again.

Hope that brought some light to your problem
okouya
okouya
the problem with moving is that i don''t have any velocity vector any acceleration vector because i dont know how to use them.
that''s a big problem for me because i have some collision detection to whrite and my player don''t move with any velocity or ect...........
and i know that my player will have to have the same velocity that have the camera.when moving.so i think that my camera class have will have to have a real velocity you.
because now, the velocity vector of my camera is just the differance between my view piont and my positin.and i know that this will not work when tying to make collision, plus i wanna write a movement with time.

love and peace
love and peace
_DarkWIng_
_DarkWIng_
STFW

There are more worlds than the one that you hold in your hand...
You should never let your fears become the boundaries of your dreams.
coelurus
coelurus
Handling movement and stuff doesn''t require much work, the problem is that you''ve programmed it all a little strange (in my opinion )

Let me give you some advice:
Only put camera-relating stuff into your camera-class. Rotation, translation and such.
Next, create a new class called player or similar. Then, add all input here, like viewing angles, acceleration, jumping etc. Just an advice though...

The acceleration is just a new speed variable starting from 0. When no keys are pressed, this variable shouldn''t change at all. But when the user does press a key, ie the forward key, start incrementing the speed-variable until it reaches top speed. As quick as no keys are pressed, decrement the speed down to 0. That''s all, isnt it?

But still, I don''t see the big problem. I don''t know how you''re making your game (fps?), so I cannot give you any direct answers. And don''t only rely on answers from people here, try to figure something out meanwhile... Which I hope you do
okouya
okouya
ok i anderstands i''m gonna try what you say.
but just an explanation
for the velocity or to move the camera i have to put the same velocity that have my player
and for the rotation too.
so i''m gonna try it like this like you say
the things is that i wanna do a game in that my player is just in front of my camera: a tomb -raider like view.
ih you have some code to give me for example i''m gonna try with that.
thanks


love and peace
love and peace

Topic Locked

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

Sign in to reply to this topic.