Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Move an object only using velocites

Author
Message
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 19:53
Hey guys, i wondering if anyone knew how to move an object only using velocites. I've about 90% of the code done, so far i got walking forward, walking backwards,walking left,walking right... the one thing i can seem to figure out is strafing. The object can only move forward,backward,left,right and cant strafe.

Here is my code, ill explain it below:


Alright so basically what i am doing, is using the gdks built in move object commands. First i get their position, then move the object, then get their positions again. After that i find their velocities by subtracting the two. After that i set the objects acceleration using the setobjectlinearvelocity function. Basically everything should be working fine but strafing isnt. Does anyone know what im doing wrong?

Thanks in advance!
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 20:30
What exactly IS happening?
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 20:34
Basically im trying to make an ODE character controller. I've posted a demo below, so you can take a look at that, and you can see the character wont strafe but can only walk forward,backward,left,right. The ode object can only be moved around by setting its velocity. In the code posted above, i am doing exactly that... but for some reason i can get the object to strafe.

Attachments

Login to view attachments
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 20:39 Edited at: 25th Feb 2010 20:39
I dont have visual studio on this pc it will be a couple hours before i can actually look at your project,

Are you using the same key for "left" and "strafe left" ?

So if i understand correctly, when you want to strafe left, you press your "left" key, which is the same key to "turn left", it doesnt strafe just turns?
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 20:43 Edited at: 25th Feb 2010 20:55
Sorry for double post but i wanted to grab his attention again,

I just ran your program and when i press A it strafes left and when i press D it strafes right ;P

EDIT: ohhh or do you mean it wont strafe while you are currently moving?? cause it doesnt do that. lol


EDIT: EDIT: Where is 'ODE_SetObjectLinearVelocity()' coming from, did you create this?
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 20:55 Edited at: 25th Feb 2010 20:56
Yes, i mean strafe while im moving... I cant hold down w and d and strafe left... As you can see, it still has a lot of bugs.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 20:56
Where is 'ODE_SetObjectLinearVelocity()' coming from, did you create this?
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 20:56
Yes that is a function i created in my own ODE wrapper.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:02 Edited at: 25th Feb 2010 21:02
If you were to comment out 'ODE_SetObjectLinearVelocity()' from the W and A then test? cause without that the sphere should still move just not as pretty?
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:05 Edited at: 25th Feb 2010 21:08
See, the thing is you need ODE_SetObjectVelocity() to move the object... Since im using a physics engine you have to move the object in the physics engine, not in darkgdk. My wrapper takes care of doing all that. Im only using dbmoveobject just for its funtionality of being able to move an object in the direction it faces. All i want from it is its values it outputs.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:11 Edited at: 25th Feb 2010 21:15
I think your problem may be above me, the only thing that is coming to mind now is that you are not repositioning the GDK object back in its origional place after figuring out the new position for moving it 'forward' understand? so with every movement your GDK object and physics object get further and further apart causing conflicts with being able to call your ODE function twice in the same frame??? thats the best i can come up with, i hope you understood.

Try changing
to



Hopfully it will still move at all, if not i havent a clue what im talking about xD.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Feb 2010 21:17
I think you should only use this once:

at the end of all the key checks.

You should declare disX and disY (displacement) once at the start and the just increase or decrease them as your 'key pressed' conditions see fit.

I have not ran your code or antything so I may be missing the point but I think it will help.

kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:18 Edited at: 25th Feb 2010 21:19
Matty is completely correct, you should do that anyways even if it isnt the issue to cut down on code and executions.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:21
Yea i was thinking the same thing too matty... But how could i compile all the positions and such so i only need to run that function once?
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Feb 2010 21:27 Edited at: 25th Feb 2010 21:28
You do it very similar to the way you have done it so far accept this:


May become:



I think you should change 'oldposx' to 'newposx' lol as this is the 'would be new' position of the object.

kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:29 Edited at: 25th Feb 2010 21:32


something along those lines

EDIT: changed codiez
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:30 Edited at: 25th Feb 2010 21:31
So then after i do all that, would i only call ODE_SetObjectLinearAcceleration() once at the end of all this and input the disx and disz in the acceleration function?

EDIT alright, let me try that kklouzal
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:33
WOOO!!!! Thanks guys sooo much! I have been working on this forever, and now it finally works! Thanks soo much again!
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:33 Edited at: 25th Feb 2010 21:34
I changed the code to get rid of that else statement completely on the W key

EDIT: doesnt it look so much more clean?
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:33
tee hee hee
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:36
Alright now one more thing... Since you cant change the postion in dakrgdk, when i use dbmoveobject, it moves the object a little then stops and stays there then when i release the key, the object goes back. How can i fix this? You can see this issue in the demo.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 25th Feb 2010 21:38
Yep I have the same issue, its like the object accelerates faster than the camera can lol, if you figure it out let me know
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:39
I may setup a variable system that stores if the dbmoveobject function is used, then if it is at the end of the function it will sett it negative so it will look like it has never moved.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Feb 2010 21:44
I think you need to:

---move object if key pressed
---change disX and disZ values
---move object back

binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 25th Feb 2010 21:44 Edited at: 25th Feb 2010 21:45


There we go, now everything is working fine! Object doesnt move anymore in a weird way! Im not sure that is the best way thoug because of the delay between wehn you set it and set it back.

Login to post a reply

Server time is: 2024-10-05 16:23:39
Your offset time is: 2024-10-05 16:23:39