Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: How can I make a sprite move from one location to another on an ARC?  (Read 2629 times)

0 Members and 1 Guest are viewing this topic.

Jyujinkai

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 351
    • View Profile
    • Jyujinkai's WME Development Blog

I am trying to do somthign that seams simple but I can not get it to work.

What I am trying to do is move a sprite from one point on the screen to another and CURVE while doign it instead of movign alogn a strait line.

Any ideas on hwo to do this?

I have this code... but it returns a wonky curve... mabey it can be improved or there is another way to do this?

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   var FireBall = Game.LoadEntity("actors\fireball\fireball.entity");
  4.   FireBall.X = actor.X;
  5.   FireBall.Y = actor.Y - actor.Height;
  6.   FireBall.Active = true;
  7.   var Slope =  (this.Y - (actor.Y - actor.Height)) / (this.X - actor.X);
  8.   var curve_size = 3;
  9.   Game.Msg(Slope);
  10.   while (FireBall.X  <  this.X) { // shoot left 
  11.         FireBall.X = FireBall.X + 4;
  12.         FireBall.Y = FireBall.Y + 4 * Slope;
  13.         FireBall.Y = FireBall.Y + Math.Sin( (-1*180)* FireBall.X / ( actor.X - this.X ) ) * curve_size; 
  14.         Sleep(20);
  15.   }
  16.   while (FireBall.X > this.X) { // shoot Right
  17.         FireBall.X = FireBall.X - 4;
  18.         FireBall.Y = FireBall.Y - 4 * Slope;
  19.         FireBall.Y = FireBall.Y + Math.Sin( (-1*180)* FireBall.X / ( actor.X - this.X) ) * curve_size; 
  20.         Sleep(20);
  21.   }
  22.   FireBall.Active = false;
  23. }

This code takes the X,Y of the player actor as one point to move teh sprite from and the X,Y of the spriet entity that you click on as teh XmY of where the sprite is ment to end up.

Demo Of how it is now
Source used in Demo
Logged
<Antoine de Saint-Exupéry> In any thing at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away...
<Carl Sagan> If you want to make a apple pie from scratch. You must first... invent the universe

Jyujinkai

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 351
    • View Profile
    • Jyujinkai's WME Development Blog
Re: How can I make a sprite move from one location to another on an ARC?
« Reply #1 on: January 05, 2009, 02:48:45 AM »

Ok, I have finaly found a solution for this... i have no idea if it is correct or if tehre ie a better one... but it works.. so screw it... If you wish to use it feel free!!

How it works... (Have a look at these pics)



You have 2 known points on A-B on the X,Y Plane of screenspace.
Say your Actor and what ever your actor is thorwing somthing at.

You also create a value for D. This is the angle that determins the height of the curve. The closer this value is to 0 the flatter the curve will be , the closer it is to 45, the more rounded it will be.... no idea what is beyond 45... but 45 makes a perfect circle, with the line from a-b teh diameter.

So a good idea is that you can set up some code to make D a value based off the distence of the A and B from each other... or w/e. This angle is made up and the code uses a variable for D, so you can manipulate it somehow if you like..

Anyway.

Once you have A,B and D values you can use them to find the location of H (see drawing)
Once you have A,B,H you can use these values to find the exact center (C) of the circle whos arc passes though A,B and H.
Once you have A,B,C,D,H You can work out the X,Y location of every point along the arc that connect A,B,C.

Ok... how dose this work?

Well, I have made a small demo scene for you. So just have a look though it.

All the code is in a few places, each button acivates a step of the code, and all teh variables are stored in BASE.INC for ease... there is some work to get this code working in a real enviroment... but well... the math works so it is just playign about and buildign functions and methods and tuff from it....

So Have fun!!!


Source Code of Curve Demo
ExE Demo of Code to Curve


Again, Thanks to Jerrot, Od, Mnem and Sound.
Logged
<Antoine de Saint-Exupéry> In any thing at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away...
<Carl Sagan> If you want to make a apple pie from scratch. You must first... invent the universe
 

Page created in 0.036 seconds with 21 queries.