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.

DarkBASIC Professional Discussion / Moving One Object On Top Of Another

Author
Message
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 22nd Mar 2011 06:15
Okay, I feel stupid asking this, but I've literally spent about 6 hours trying to figure this out. I want one object to "ride" on top another, but I can't figure out how for the life of me. I've come close using trigonometry but the object on top slowly moves towards the center of the other one. Here's a quick sample to demonstrate what I mean and that I would be very grateful if someone could modify so it would work or at least explain how to do so:


The red box (controlled with wasd) is obviously supposed to "ride" on top of the white one (controlled with arrow keys). And it does until you turn, and that's where everything is messed up. I know why this solution doesn't work, but I can't even figure out where to start with one that does. Any help is appreciated, thanks.


Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 22nd Mar 2011 09:11 Edited at: 22nd Mar 2011 09:45
I don't see what you are describing. I run your code, move the white box all over the screen, turning left and right. The red box stays put on top of the white box. When I move the red box, it stays at the exact offset that I've moved it to. I see no slow movement towards the center of the white box.

Of course, since your offset doesn't take into acount the angle of the white box, the red box shifts from the position of the white box only.

I added this to your loop:



and the offset never changes unless I change it.

An easier way to have it follow might be to glue the red box to the white box.

Thus:


Or is that not the behavior you want?

Oh hey! I'm in Texas too, down Galveston way.

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 22nd Mar 2011 19:08 Edited at: 22nd Mar 2011 19:10
Thanks for the response.

Sorry, I don't think I described what I want very well. To give it context, I'm trying to get a player to move with a ship, while the ship is moving. So the player should be able to move around relative to the ship as well as being moved by the ship. The result of the glue object command is what I want, but the problem is that I want to be able to move red object that's on top around while the bottom object moves as well (in the case of the ship, the player).

Quote: "
Oh hey! I'm in Texas too, down Galveston way."

Nice, I live north of Dallas, but go to school in Waco .

EDIT: Gah, just tried it again, and it seems you CAN move while glued to an object, which is what I want! So, now the question is, if I use this to glue, say, 100 objects to an object, how will the performance be? I'll try out some tests and see, thanks for the help!


Admiral MH
15
Years of Service
User Offline
Joined: 10th Feb 2011
Location: TX, USA
Posted: 22nd Mar 2011 20:03 Edited at: 22nd Mar 2011 20:04
Quote: "EDIT: Gah, just tried it again, and it seems you CAN move while glued to an object, which is what I want! So, now the question is, if I use this to glue, say, 100 objects to an object, how will the performance be? I'll try out some tests and see, thanks for the help!"


It takes very little time to glue objects, for my computer it takes only 3 milliseconds to glue 200 objects.



Quote: "Nice, I live north of Dallas, but go to school in Waco ."


Wow 2 Texans on the forums, nice to see that as I also live in Dallas.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 23rd Mar 2011 01:47
Hmm, well now the problem is that it doesn't seem to actually update the position of the object on top, so when doing calculations with that or doing something like collision, it won't work. Working on trying to figure out another way to do it now, but if anyone can figure it out sooner, that'd be nice.

Quote: "Wow 2 Texans on the forums, nice to see that as I also live in Dallas. "

Ah, nice, I guess this is a thread of Texans .


Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Mar 2011 02:23
Are you going to be moving and rotating the object on all axes? I've made a general solution before (Errm... I forget... maybe part of it didn't work? xD) and posted it on the forum, then someone else asked again and I linked to it... maybe I'll just write something up and post it on code snippets.

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 23rd Mar 2011 02:32
Quote: "Are you going to be moving and rotating the object on all axes? I've made a general solution before (Errm... I forget... maybe part of it didn't work? xD) and posted it on the forum, then someone else asked again and I linked to it... maybe I'll just write something up and post it on code snippets."

Ideally it would work on all axes, but it would be nice to even get it working on moving in the x and z axis and rotating on the y axis.


Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Mar 2011 03:10 Edited at: 23rd Mar 2011 03:16
I've got examples of how to do this using trig/matrix and by using limbs. Don't have a clue where the they are at the mo, so I quickly wrote a limb one using the offset limb command.



I could make this more efficient but I think you can work off this. Using limbs in this way is handy, since it's works similar to using forward/right and up vectors to move objects. So in a sense you could use this for cameras or anything really.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 23rd Mar 2011 03:40
If you were to move the ship by using vector addition, then you could apply the same vector to each passenger.

So, for example, if the ship is moving +3.5 x and -1.1 z every unit of time (whatever time unit you use), then apply the same movement to each rider. Then let the passenger move, then display the results.

At least, I think that might work.

I don't know a lot about vectors, but maybe it's time to learn. I'll try to post an example.

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 23rd Mar 2011 04:34
Thanks for the responses .

Quote: "I could make this more efficient but I think you can work off this. Using limbs in this way is handy, since it's works similar to using forward/right and up vectors to move objects. So in a sense you could use this for cameras or anything really. "

That definitely is on the right track, but now the problem is calculating the initial offset if it's not predefined and the ship is rotated. I modified your code as an example:

Press space to activate sticking to the object. As you can see, if you don't rotate the white box, there are no problems. But if you rotate the white box and then activate it, it throws off the offsets. I'm trying to figure out the new offsets using trig, but a combination of a fried brain and terrible math skills isn't working for me.

Quote: "If you were to move the ship by using vector addition, then you could apply the same vector to each passenger.

So, for example, if the ship is moving +3.5 x and -1.1 z every unit of time (whatever time unit you use), then apply the same movement to each rider. Then let the passenger move, then display the results.

At least, I think that might work. "

I've actually done that already, and it works...until you turn the ship, which then throws off the offsets .


Mr Bigger
21
Years of Service
User Offline
Joined: 31st Jan 2005
Location: was here!
Posted: 23rd Mar 2011 17:33
That all looks over complicated to me.

See if this could work for you.


AMD 2600+/1GB ram/GeForce 6600oc 256MB/W2KPro/DBPro 6.6.b
Avoth
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location:
Posted: 23rd Mar 2011 18:35 Edited at: 23rd Mar 2011 18:43
This may possibly be the most n00b reply yet. My first thoughts would be to create a large hit box around the ship (extruding out above deck) so when object-player move inside this hit box, the ship becomes the new terrain. Edit player movement to check for vehicle terrain hit box >

if inside hit box then player movement relevent to ship
Else Player movement as normal relevent to terrain

Please dont heckle me for what is possibly an extreme noob reply. Just throwing my thoughts into the picture.

My worry being that when you come to allowing your player to transition from ground to ship... and your using collision checks with ground to determine if your player is on terrain or a ship.. if the player should there will be 0 collision and the ship may sail off leaving the player in the middle of the Atlantic!
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 23rd Mar 2011 19:28 Edited at: 23rd Mar 2011 19:29
Quote: "That all looks over complicated to me. "

That's what I keep thinking, but the problem comes when you add not knowing what the initial offset is and having to calculate that. Here's an image to show what I mean:


So you have the player off of the ship in the first frame, and you don't care about the offset because he's not on the ship. Then you have him move onto the ship in the second, and this is where you have to figure out what his offset relative to the ship is, and attach him at that position, which is what I can't figure out how to do. Like I said, I somewhat did it using trig, but apparently it's not precise enough because the player slowly moves towards the center of the ship. Now that I'm describing this though, I may have an idea, so I'm going to try that.

Quote: "
This may possibly be the most n00b reply yet. My first thoughts would be to create a large hit box around the ship (extruding out above deck) so when object-player move inside this hit box, the ship becomes the new terrain. Edit player movement to check for vehicle terrain hit box > "

Haha, well, I don't see how that would help with offsetting the player with the ship .


Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 23rd Mar 2011 20:02 Edited at: 23rd Mar 2011 20:50
EDIT: Okay, I think I've got it working now.

Once I realized that the "passenger" will always be in collision with the "ship" (since the the ship's bounding box is MUCH bigger than just the deck) I got a grip on the problem.

Basically,

1. Any part of the ship that needs to be checked for collision needs to be a seperate object that follows the ship. Thus the railings are not part of the ship model, but move with it.

2. Glue a dummy object to the ship for each passenger.

3. Use the dummy object to position the passenger. Movement keys move the dummy object, then the passenger is updated.

4. Check the passenger against the rails for collision, but move the dummy object away from the rail, not the passenger.

Thus;




This doesn't do anything for getting the passengers on the ship, but it does let them walk around while the ship is moving.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Mar 2011 20:43
Hmm... stuff it, I'm gonna use Quaternion's for this. Eular sucks when it comes to rotations. Post something later.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 23rd Mar 2011 21:07
LOL - I added a dock...



But you gotta get on the boat before it moves. Otherwise, well, it's just silly.

kamac
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 23rd Mar 2011 21:25
Hm Hm Hm. Just a quick idea, i dunno if it could really work.

-Check if player collides with boat, if yes, then get his relative position to the boat's offset. (I don't now know how to really do that, but there must be a way )

-Keep placing the player at the position, so example:


That's just the way i'd do it The client won't be able to see his player rotating in ship's direction and then back to it's direction because of sync . Really, i would do it this way .

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 23rd Mar 2011 21:53 Edited at: 23rd Mar 2011 21:54
Well, I've finally figured out a way to do it, haha.

Quote: "EDIT: Okay, I think I've got it working now.

Once I realized that the "passenger" will always be in collision with the "ship" (since the the ship's bounding box is MUCH bigger than just the deck) I got a grip on the problem.
"

Nice, that seems to work too, I'll take a look at it and see if it's better than what I have, thanks .

Quote: "Hm Hm Hm. Just a quick idea, i dunno if it could really work.

-Check if player collides with boat, if yes, then get his relative position to the boat's offset. (I don't now know how to really do that, but there must be a way )"

That's along the lines of what I've been trying to do, but this:
Quote: "get his relative position to the boat's offset."

was my issue, which I've FINALLY solved. I was using trig to do it, and it was somewhat right, but the calculations were slightly off (I guess because of precision problems, so something like .0000099 became .000001), causing the player to slowly drift towards the middle of the ship. But then I realized, I don't need to calculate the offset every loop the player is on the ship, only when he gets on, and then adjust the offset based on the keys he presses, minimizing the effect of inaccuracies in the calculation. So here's what I came up with:


If you press space, you stick to the ship, and if you press it again, you release from it. So this seems to be one solution to the problem, but if anyone has anything better, feel free to post it, thanks for all the help .


kamac
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 23rd Mar 2011 21:57
Quote: ""get his relative position to the boat's offset.""


And this feeling i did help somehow my top awaited game

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Mar 2011 07:14 Edited at: 24th Mar 2011 10:04
[edit]
I figured out what I was doing wrong. I should have a working demo and a nice system up shortly.
[edit2]
posted.
http://forum.thegamecreators.com/?m=forum_view&t=183236&b=6

Login to post a reply

Server time is: 2026-07-17 12:04:43
Your offset time is: 2026-07-17 12:04:43