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 / Hovering Objects

Author
Message
kordman916
16
Years of Service
User Offline
Joined: 5th Oct 2007
Location:
Posted: 3rd May 2009 07:32
How would I make an object "bob" up and down like it's hovering

Izzy545
20
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 3rd May 2009 07:55 Edited at: 3rd May 2009 07:55
There are multiple solutions for this. Here's one. We store the initial height in variable starty# and how high/low it bobs is stored in bobheight#. This code assumes the object is object 1 and "up" is on the y-axis.

Based on position:



and in a sample program:



Hope that helps. Obviously it's a very basic bobbing up and down, you'll probably want to smooth it out some, but it's a start.

kordman916
16
Years of Service
User Offline
Joined: 5th Oct 2007
Location:
Posted: 3rd May 2009 09:31
How would I go about smoothing it out?

Izzy545
20
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 3rd May 2009 10:09 Edited at: 3rd May 2009 10:11
Well, I think slowing it down at the bottom and at the top of the float cycle looks a little better. There are some maths involved and as I'm not very good I wouldn't be able to give you a good function to do so, but I did modify the code a bit so it bobbed slower, slowed down a bit at the top and bottom (not in the way I imagined) and bobbed less, looks a bit better. Here's the code:



Essentially we're taking the current height, modifying it by where it started from and how high it's supposed to go, and getting a multiplier from it. Even if you don't know maths, think about a workaround to get the result you want and you'll probably be able to come up with SOMETHING like I did

Good luck!

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 3rd May 2009 15:59
maybe something like this? its very simple



(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
kordman916
16
Years of Service
User Offline
Joined: 5th Oct 2007
Location:
Posted: 7th May 2009 04:34
how would i slow it down

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 7th May 2009 08:33
you have the MaxSpeed# = 2.5 variable, if you adjust it, it'll slow down

i forgot to ad something to the last code, this one is better



(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 8th May 2009 15:02
Try this more usable and more elegant way:



There is always one more imbecile than you counted on.
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 8th May 2009 16:28
very good, i don;t understand it, but its better than my code

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 8th May 2009 16:54 Edited at: 8th May 2009 16:55
which part you dont understand?

This function is same as wrapvalue() in DBPro
It just fakes the n variable as global and adds the spd variable to it every loop and wraps it to 0 if its bigger than 360


This function uses cos() of the above n variable(360 degree angle in this case) and smoothly intervals it between the given range


and below part in the main loop;
ang# is the angle i mentioned above(wrapped variable)
y# is the value which we smoothly interval between 20 and 40 back and forth
0.5 is the speed of wrapping thus effects the hovering speed


Hope its more clear now.

There is always one more imbecile than you counted on.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 8th May 2009 17:13
This one shows how to use different speeds for different cubes


This one shows how to use different height ranges for each cube


There is always one more imbecile than you counted on.
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 8th May 2009 20:13
ok now i get it, i thought the ang# variable was a real angle value, but its not i think

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 8th May 2009 21:58 Edited at: 8th May 2009 21:59
well, it is a real angle value. in this case.

There is always one more imbecile than you counted on.
kordman916
16
Years of Service
User Offline
Joined: 5th Oct 2007
Location:
Posted: 9th May 2009 04:05
Hehe, thanks guys this helps alot.

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 16th May 2009 23:16
Cucumber, i use your code in my game ok? i'll put you in teh credits

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!

Login to post a reply

Server time is: 2024-09-28 06:26:03
Your offset time is: 2024-09-28 06:26:03