Trajectory line

Get help using Construct 2

Post » Thu May 24, 2012 9:07 pm

Howdy,

I am working on a project that calculates the X,Y of a sprite in relation to a static object's X,Y to calculate the force of a launch (think a particular game involving unhappy birds..). That's all configured and whatnot but one thing I would like to add is a line that predicts the objects trajectory.

I can do it right now by just launching another object from the static sprites X,Y using the force calculation but I'd rather have a trajectory line than an object doing this. Any idea how I could go about this?
B
2
Posts: 2
Reputation: 354

Post » Thu May 24, 2012 9:30 pm

You can keep launching objects (white dots or something) and have them deleted when they hit something.
They are just created when the player is clicking on the "bird".
You calculate the dots speed and angle the same way you do with the "bird".

Edit: I guess you are still using objects but since the dots don't affect what you are throwing the birds at I thinks it's a good solutiontomasabril2012-05-24 21:35:18
B
18
S
1
Posts: 19
Reputation: 1,473

Post » Thu May 24, 2012 9:33 pm

When I do that in my space shooter game I fire a projectile every .3 seconds and spawn a marker at its position every tick. I limit the length by counting the number of markers that are showing. ( I have some markers as well as the projectile used for trajectory set to invisible).

You can see it in action here -- http://www.m2ag.net/dev/shooter/

Enter the game and try the dev game. The trajectory line appears when you click on the bar at the bottom and pull down (shoot sort of like a sling shot). The trajectory line responds to the magnitude of the pull, and give and indication of travel around the gravity obstacle in the middle. marcgram2012-05-24 21:34:58
B
330
S
7
G
2
Posts: 27
Reputation: 10,791

Post » Thu May 24, 2012 9:54 pm

@marcgram - is that trajectory line curved? If not, I can't think of any way to do it other than tomasabril's way. You could make these dots fade out before hitting the ground.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu May 24, 2012 10:47 pm

Yes, it curves for the gravity obstacle. There is no gravity in the game except around that.

That is why I made it, so people would have an idea where the shot would go when encountering an obstacle.
B
330
S
7
G
2
Posts: 27
Reputation: 10,791

Post » Fri May 25, 2012 5:21 am

Hmm, if that doesn't work, try using some physics equations! To get you started, observe that during your trajectory, your object's coordinates will change as follows (from physics equation for an object under constant acceleration i.e gravity):

y(time) = initialYSpeed * time + ( acceleration * time^2 ) / 2
x(time) = initialXSpeed * time

To show your trajectory, just run a loop for (time = 0) to (time = 10) or something similar, and create a circle at your calculated y and x, using loopindex as 'time' in those equations. Experiment until you get the result you are looking for. You'd be best off using small 'circles' that make up the path instead of wanting a continuous line. You can either destroy all the circles every tick, or use a set amount of circles and position them each time. I can try doing an implementation if that will help. But I'll only be able to get to it in a couple days.
Dalal2012-05-25 05:23:45
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Fri May 25, 2012 2:06 pm

An example would be great when you have the time, math was definitely never my strong suite.
B
2
Posts: 2
Reputation: 354

Post » Fri May 25, 2012 9:23 pm

@Dalal

That is the approach I wanted to take initially, but found it too difficult to account for the effects of other bodies having gravity. So doing the ballistic ranging kind of thing works best for me in this case. In this application it predicts the path of the projectile pretty accurately, once you get the knack of reading it.

marcgram2012-05-25 21:25:33
B
330
S
7
G
2
Posts: 27
Reputation: 10,791


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 1 guest