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 / Make object follow curved path (not Bezier)

Author
Message
Erik
21
Years of Service
User Offline
Joined: 22nd Feb 2005
Location:
Posted: 28th Jul 2012 16:52
Hey guys,

I've searched to no avail... If someone could point me in the right direction I'd be very grateful

Supposing I have the distance between object A and object B...
If I wanted to "shoot" a bullet from object A to object B but I wanted this bullet to arc up into the air and then land right on object B... how could I accomplish this?

I thought the answer lied in taking the distance and calculating the arc using 1/2*pi*diameter(or distance in this case) but that gives me the arc length only (of a circle with a diameter of the distance between the two objects)... I'm at a loss to figure out the curve info and how to make a routine that steps the bullet along that path.

The distance between the objects is dynamic so the code need to account for the distance being variable... and I'd like to be able to make the height of the curve (the apex of the bullet's travel before falling back down towards object B) variable as well...

I hope that all makes sense... any help is much appreciated...

Every absurdity has a champion to defend it.
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 29th Jul 2012 02:41
You're looking for more of a parabolic curve.
Basic form: -((rate)T - (offset))^2 - (desired height)

Hopefully someone whose brain is working a bit better than mine right now will come along and show you a way to get the parameters set up right.

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 29th Jul 2012 03:39
What Dar13 said was correct, the path will be a parabola, assuming that only gravity is acting on the bullet.

However, you can do this without having to know the equation of a parabola. They I do this is to split the velocity of the bullet into it's horizontal and vertical components, which would be based on the angle of the gun. If only gravity acts on the bullet then the horizontal velocity will be constant and the vertical velocity will change with gravity (to make things easy we'll assume gravity is constant).

Below is a demo showing a way to implement this.




This is a 2d demo but the basic concept will work in 3d.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Jul 2012 06:59
Check out the 'projectile motion' equation under 'misc'.
http://www.dbcodecorner.com/?page=eq

And here's an example I did that implements that method:
http://www.dbcodecorner.com/showcode.php?entry=218

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Erik
21
Years of Service
User Offline
Joined: 22nd Feb 2005
Location:
Posted: 29th Jul 2012 18:40
Wow! Great feedback guys... thank you very much...

I'm still having some issues applying all of this into 3D. Here's an upload of the code I'm working on:



The angles involved are of the line formed between the 3D mouse and base...(top down view so there really isn't a y axis defined by the user).

[img]null[/img]

In the end, what I'm hoping to accomplish is: the bullet shoots from the 3D mouse and lands right on the target, but by following a curve up in the air rather than bee-lining right at it. Does that make sense?

Every absurdity has a champion to defend it.
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 31st Jul 2012 00:44
I've had a look at this and, well, I'm struggling a bit. I spent some time thrashing around with the equations Phaelax mentioned and it was getting a little complicated. It was one of those problems that looked easy but kept slipping awat. So I looked it up on wikipedea.

http://en.wikipedia.org/wiki/Projectile_motion

If you look at the parabolic trajectory equation, we either need to:

Calculate the angle a# of the "canon" for a fixed speed v# of the "ball" when it's fired. This is what I would prefer to do.

Or

Calculate the speed of the "ball" for a fixed angle of the "canon".

I don't know about you but trying to rearange that equation to calculate the angle based on a known speed didn't look like fun (but I suspect that it's possible and someone brighter than might be able to work it out).

So if we fix the angle of the canon then we can rearange the equation to calculate a speed the ball need to be fired at.

Below is a demo that I lashed together:



The one thing I couldn't get working correctly is if the target and the canon are at different heights. This may or may not be something you require but I'll have a bit more of a play.

Anway, that's as far as I've got so far.
Erik
21
Years of Service
User Offline
Joined: 22nd Feb 2005
Location:
Posted: 31st Jul 2012 02:48
Hey all,

I've got it! I was able to get a decent projectile working using the framework 29 games provided above.

Many, many thanks to all who came to my aid

Every absurdity has a champion to defend it.

Login to post a reply

Server time is: 2026-07-07 12:26:19
Your offset time is: 2026-07-07 12:26:19