The Daily Click ::. Forums ::. Non-Klik Coding Help ::. How to calculate a point on a line?
 

Post Reply  Post Oekaki 
 

Posted By Message

Eight Bit Battle Cat



Registered
  08/09/2002
Points
  967

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
8th February, 2012 at 21:16:42 -

Hey, I'm hoping you guys can help me. What I need to do goes beyond my math skills, and I'm not sure what to search for so here goes.

I'm playing around with physics in Construct. I've made a grenade that the player can toss. After some time it explodes. I want it to be so it pushes other objects and they fall (they have the physics behaviour as well).

What I want to do is push objects with force, towards a point that is determined by where the center of the explosion is:

Image

1 is the center of the explosion, the circle being the area the explosion affects.
2 is the object that is being hit.
3 is the point I need to find, so I can make an event that says to push the object (2) towards point 3.

I'm guessing it has something to do with sinus or cosinus but I'm at a loss.

 
Check out my dungeon crawler Princess In Another Dungeon - http://ebbc.dk

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8234

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
8th February, 2012 at 21:59:43 -

If Construct has ATan2 to solve for the angle of a line, then the following pseudocode should apply:

angle = ATan2(y2-y1,x2-x1) // equal to the angle of the line

deltaX = cos(angle) * distance // distance is the distance you want the object to move
deltaY = sin(angle) * distance
targetX = x2 + deltaX
targetY = y2 + deltaY


You use ATan2 to find the angle of that line, then use the cosine of that angle to get the change in X and the sine of the angle to get the change in Y.

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Eight Bit Battle Cat



Registered
  08/09/2002
Points
  967

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
11th February, 2012 at 00:18:23 -

Thanks for your help, I was able to get it to work. It might need some tweaking though, but here is the immediate result:

http://dl.dropbox.com/u/2776515/SpaceMiner01.avi

Edited by Eight Bit Battle Cat

 
Check out my dungeon crawler Princess In Another Dungeon - http://ebbc.dk
   

Post Reply



 



Advertisement

Worth A Click