Parabola/Tracjectory tracing with Physics / Box2D

0 favourites
From the Asset Store
Game for kids for tracing letters. A simple game for tracing letters.
  • R0J0hound

    Can we reverse the direction of the mouse? So when we move the mouse backward, the parabola move forward,and vice versa. And when we move the mouse down, it gets higher, and vice versa. Thanks <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Hi, it doesn't work with Touch... How we can use Touch and remove Mouse?

    Thanks! :)

  • You can replace the events, be aware though that touch will revert to 0,0 when not 'in touch' so it will act a little differently to what you may expect.

    If you're using touch, you may want to have a second invisible sprite and use its x/y coords instead, and have it update its position to the touch position only when in touch.

  • bon4ire

    Do you have any solution for your own question because I m also get the same query. I changed all mouse event into touch event after that ball is not launching..

    Do you have any idea how to resolved it............

  • Hi! Rojo's example for calculating trajectories is great! Just what I needed. Now I'm applying this to a game centered on jumping and would like to limit the extent of the trajectory so that it will only extend to a certain point and won't follow the mouse beyond that point on both x and y axis. Does anyone have any advice on how to do this? My starting point is Rojo's example :)

  • For the undamped version add an action to the top of event 4 to set step to mouse.x/vx/11.

    Or in general:

    (targetx-startx)/vx/loop_length

    For the damped version it is more complicated. The basic objective is taking the equations for x and y positions and solving for the time when x and y are at the mouse.

  • Hi guys,

    I have read your topic, ad I have tried to understand how your exemple run. I have made a clone but the parabole doesnt work, I don't understand why

    Can you help me please

    You find my example here: https://www.dropbox.com/s/yzulswlnjrxgh ... .capx?dl=0

    thanks a lot

  • JohnnySix Would you share the capx for the tank example?

    thanks,

  • For the undamped version add an action to the top of event 4 to set step to mouse.x/vx/11.

    Or in general:

    (targetx-startx)/vx/loop_length

    For the damped version it is more complicated. The basic objective is taking the equations for x and y positions and solving for the time when x and y are at the mouse.

    i know this is old but this is the best example of how to do a parabola, is there a way that i can change the even that launches the ball for an input? when i do it it doesnt work, for example "on touched object" as i want to do a button on screen that launches it, i also tried with functions but didnt work.

  • IJCT

    Best I can tell from looking at the events is they have to be done in order, and triggers can be run at any time.

    Basically the the three events are:

    "every tick" which calculates the stating velocities

    "the input check" which launches an actual physics object with the calculated velocities

    "the loop" which takes the calculated velocities and simulates physics steps to find the path of the ball.

    So if you want to launch a ball with a trigger such as a function you need to run the every tick event first somehow. Could be as simple as copying it.

  • IJCT

    Best I can tell from looking at the events is they have to be done in order, and triggers can be run at any time.

    Basically the the three events are:

    "every tick" which calculates the stating velocities

    "the input check" which launches an actual physics object with the calculated velocities

    "the loop" which takes the calculated velocities and simulates physics steps to find the path of the ball.

    So if you want to launch a ball with a trigger such as a function you need to run the every tick event first somehow. Could be as simple as copying it.

    thanks! i did figure out a way to do it, im doing an angry birds clone just for learning so thats why i was needing the help, what i did it was this:

    this can simulate a trigger input, so if everyone needs help doing this, they can just do that (the variable "resortera" means slingshot in spanish is just a condition for a state in my project so you can ignore it)

    thanks a lot for the capx, it helped me a lot, i did some small modifications to it to have a more realistic angle and i may upload a demo so everyone can see the small tweaks i did

  • Hey R0J0hound,

    just discovered this thread when searching for an impact prediction for a bullet-behaviour-controlled object.

    I tried to apply your calculations to my project, but that didn't quite work out, since my setup is a bit different compared to yours.

    Can you help me with this? (Image of current setup further down)

    I have the following scenario:

    A projectile with the bullet behaviour gets shot from a specific angle (and a slightly elevated position) at a specific initial speed (400) and gets dragged down by the bullet's gravity (450).

    So the thing is, I don't set the initial horizontal and vertical speed with the mouse, but with the bullet's initial speed.

    I want to mark the impact point on the ground (at a specific y = 570) with a sprite.

    So I tried to set the sprite's position to posx,570, after repeating the loop 11 times.

    The sprite was somewhere near the impact point, but nowhere near the accuracy in your example.

    My question to you is now:

    To which number should I modify the loop count and do I even need a step value, since I don't need any trajectory displayed?

    Thanks for any answer, here is my current setup:

    http://i.imgur.com/Nrrat3j.png?1[/code:1rx64nho]("Launcher" is slightly elevated)
    (I don't expect you to deal with the mess of my capx)
    
    (Btw, I took a look at the bullet launch in the debug view and figured that on launch, the bullet's vx0 is the set Bullet.Speed and vy0 is always 0, maybe that's an issue here..)
  • randomly

    If you just want to mark the point it hits the ground then you can either just set speed to the bullet's speed or if the ground is flat you can just calculate the impact x directly by taking these two equations and solve for x:

    y = initial_y + initial_y_velocity*time - 0.5*gravity*time^2

    x = initial_x + initial_x_velocity*time

    which would be:

    x= initial_x + 2*initial_x_velocity*initial_y_velocity/gravity

    if the bullet was launched from ground level

  • R0J0hound

    Thanks for the answer.

    Actually, the launching position is higher than the ground.

    I tried applying your original formula to my project, exchanging the speed to the bullet's speed and changing all other stuff to my equivalent objects (which didn't work).

    If I now want to use the solved two equations for an elevated launch position, what shall I modify?

    And for the initial y and x velocity, should I just take the velocities from the debug mode (being x=400 and y=0 on launch)? Because the Bullets behaviour obviously doesn't allow me to set x and y velocity seperately..

    [EDIT]

    I figured I maybe have to set the initial y velocity to launching_speed*sin(launching_angle)

    and the initial x velocity to launching_speed*cos(launching_angle).

    Since my launcher's angle is somehow always set as 360-actual_angle, I also figured I'd change the launching_angle to abs(360-launching_angle). Using this, my current setup looks like this: i.imgur.com/TK4pTAQ.png

    It kinda works, but the accuracy is always ± ca. 100 pixel (horizontally) which is not exactly what I'd consider accurate...any idea what I did wrong? Is it the elevated launching position?

  • thank you for share the capx file!

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