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.

Newcomers DBPro Corner / Gliding movement over a specific distance?

Author
Message
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 11th Mar 2012 12:14 Edited at: 11th Mar 2012 12:23
Good morning fellow forum-members,

I'd like to pose a quick question to you: in these two threads I've been asking questions about step-by-step movement and camera rotation. Thanks to Quisco's help, I've been able to learn a lot about these subjects and the way DarkBasic functions. Now, I'm trying hard at reaching the 'final synthesis' of these two elements: creating a gliding movement-motion of the object during the steps.

I've been experimenting with several ways to do this. For instance, I've created a function with a FOR - NEXT loop, during which the object moves at every iteration. For some reason though, it seems the object is set directly at the end of the loop or moves to fast through it to be noticable. Instead of gliding to it's new position, the object appears instantly at it's destination. Here's an example of one of these experiments:



So, my question is: is this the proper or most efficient way of trying to program a gliding effect? I'd really appreciate help by getting a pointer in the right direction!


p.s. I hope I'm not giving the impression of wanting to be spoon-fed with answers - I like learning DarkBasic by trial and error, but at this stage I'm still getting stuck a lot.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 12th Mar 2012 13:42 Edited at: 12th Mar 2012 13:51
I'm not able to feed you as I don't understand exactly how this works. But here's my idea.

position object 1, ObjPosX, ObjPosY, ObjPosZ

That line will place the object at ObjPosX ObjPosY ObjPosZ for as many times the variable StepSpeed stands for, and then ends. This is why it pops up instantly at its destination.

You should increase ObjPosX / Y / Z in a loop, shall that be a - for next loop or the main loop.
A function and gosub do also work, as they are declared in the main loop.

I hope this gives you an idea what should happen.



This is a piece of code I have in my game, it comes with sparkys Collision DLL. I have commented it for as much as I know.

I'm sorry for the messy code. I cannot seem to get it placed correctly on the forum.
Quisco DaLuse
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 12th Mar 2012 17:02
You are wasting time by using the for - next loop like that. From your other thread, StepSpeed was set to a constant value of 10, which means you are moving a total of 0.1 screen units after ten iterations of the loop, which is an extremely small amount for the total, let alone for each iteration. It would be better to make StepSpeed a float value of 0.1 and get rid of the for-next loop.

Also, you are using the Z camera angle with NewZvalue and it should be the Y camera angle. Additionally, you need to use the NewXValue in conjunction with the NewZValue.

I have looked at the code you put up on the other thread, and I edited it so that you can move in all four directions (it will move you forward and left at the same time, for example). It does not have object 1 in it yet.



I left the difTime there, but really, it is not used. The movement seems smooth to me. I can help you with putting object 1 in place if you need it.
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 12th Mar 2012 21:50
Hi Ramon and Quisco,

thank you both for providing feedback! I'll experiment with your suggestions as soon as I can make some time (probably wednesday!) and report back.
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 15th Mar 2012 21:56 Edited at: 15th Mar 2012 23:27
Hi all,

It's been quite a hectic week, so I haven't been able to experiment a lot. This evening I've been examining Quisco's code. The example provided moves very smoothly indeed but (on my machine at least) keeps moving until a key is unpressed.

I've been trying to combine the lines above with the earlier code-examples to create a 'fusion': smooth movement in a direction once a key is pressed, but for a specific distance. After reaching the distance, key is reset to 0. For this reason I used the FOR-NEXT loop, i.e.:

When key=0 and keyboard key is pressed
for move=1 to distance
take a small step
draw object & camera
next move
Reset key when no keys are being pressed, allowing movement once more

The DifTime-variable is there because I want to make a program in which I can switch between step-by-step movement and FPS-like movement. I'm not quite there yet, but wanted to share my stuff:

Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 22nd Mar 2012 15:43
A quick follow-up (sans code since I'm not at my usual machine): I was able to sort out my problem! Turned out I forgot to call a 'sync' after each sub-step, resulting in my player object instantly appearing at the end of the total step.

Login to post a reply

Server time is: 2024-11-23 21:04:12
Your offset time is: 2024-11-23 21:04:12