Trajectory line

0 favourites
  • 8 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • 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?

  • 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 solution

  • 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 -- 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.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • An example would be great when you have the time, math was definitely never my strong suite.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)