Posts ID:885588 Favorites Medals
 ID:885588   Jul 23 2012, 10:07 am (See the best response by Kaiochao.) Problem description: How would I be able to make a projectile that has a controlled curve path? Also, one that would curve more sharply after a distance (e.g. after a certain distance moved the path would change)? I'm not sure if this would use circles, or parabolas...I'm at a loss.
 #1 Jul 23 2012, 10:43 am Wait...is a curved vector simply a vector with gravity?
 #2 Jul 23 2012, 10:55 am I don't know what a "curved vector" is, but I do know that vectors don't have gravity. Gravity is a property of mass (don't quote me on that), and vectors aren't physical objects. Do you mean projectile motion?
 #3 Jul 23 2012, 11:08 am This is exactly what I was looking for. Thanks!
 #4 Jul 23 2012, 11:11 am In response to Kaiochao (#2) Is it efficient to use Sin and Cos with projectile motion? I've heard that trigonometric functions process slowly in BYOND.
 #5 Jul 23 2012, 11:26 am In response to Cloud Magic (#4) A lot of things process slowly in BYOND. I've also heard that the trig functions are especially slow, but there's only two ways I know to set initial velocity. In Forum_account's Sidescroller library, mobs are affected by gravity (which is, in this context, another name for downward acceleration). It's just subtracted from vel_y each tick, so objects that go up (positive vel_y) eventually go back down (negative vel_y).
In response to Kaiochao (#5)
My head hurts from attempting to understand that forum post you linked me to.

I see the OP has the angle proc he is working on:
 ```proc Angle(mob/origin,mob/destination) var/dx=destination.x-origin.x*32 var/dy=destination.y-origin.y*32 var/angle=arccos(dx/sqrt(dx*dx+dy*dy)) return angle ```

Which is inefficient because he's using cosine.

 ```// Fixed by DCvar scale = speed / sqrt(dx * dx + dy * dy)dx *= scaledy *= scale ```

and I have no idea what it relates to...

I quote from Wikipedia "The components v0x and v0y can be found if the angle, α is known"

So velocity is a combination of movement along the X and Y axis...

and modifying the v0y component will give the projectile a curve...so if each tick you are decreasing the v0y component...and v0x and v0y are unit vectors? What? I thought they were components of velocity... I don't get it.

Ok ok so looking at the Cartesian coordinate system, each point on a vector is specified...so these points must be units.

So the goal would be to set the angle of the projectile to each point? How do I find these points though? And what is the purpose...or in other words, how the hell do you move an object at an angle?
 #7 Jul 23 2012, 12:42 pm In response to Cloud Magic (#6) All you really need to know about a vector is, a 2D vector has an x- and y-component. There's really nothing complicated here. As I said in another topic, a vector is just a pair of numbers. I think you're associating the concept with other overcomplicated things.
 #8 Jul 23 2012, 1:39 pm (Edited on Jul 23 2012, 2:03 pm) In response to Kaiochao (#7) Edit: nevermind, I think I get it now
In response to Cloud Magic (#8)
Best response
I could show you high school physics equations for projectile motion, or I could just tell you what gravity is in 2D games. Gravity in 2D games is traditionally a downward acceleration.

I'm going to assume you know how to add two numbers together.
Imagine a cannon firing a cannonball. In a 2D sidecroller, it could shoot northeast. Let's say the ball would have an initial velocity of <5,5> pixels per tick. Let's assume we have a gravity vector, <0,-1> (pixels per tick per tick), so the ball accelerates downward. On the first tick, the ball is shot and moves 5 pixels up and to the right. On the next tick, the ball's velocity is changed by its acceleration, and it is now <5,4>, so the ball moves 5 pixels to the right and 4 pixels up. If you keep adding gravity to the ball's velocity, it ends up being <5,3>, then <5,2>, <5,1>, <5,0>, <5,-1>, and so on. The ball started going upwards, but now the ball's going downwards.

In code, you could do this:
 ```var x = 0, y = 0 // initial positionvar vx = 5, vy = 5 // initial velocityvar ax = 0, ay = -1 // acceleration (it's not going to change here)for(var/t in 1 to 10) sleep(world.tick_lag) // shift the position by the velocity vector x += vx y += vy // shift the velocity vector by the acceleration vector vx += ax vy += ay src << "([x], [y])" ```

Using Forum_account's Sidescroller library, you can do this:
 ```var mob/ball/ball = new (loc)ball.vel_x = 5ball.vel_y = 5 ```

By default, the library has a gravity variable that decreases vel_y each tick. When you jump in sidescrollers, you obey the same "motion physics" as projectiles like cannonballs.
 #10 Jul 24 2012, 9:06 pm Here's a situation in which you can apply simple real-world physics knowledge. What is curved motion? Curved motion (in any sense) is motion along a path defined by some portion of a circular (or something more erratic like an ellipse, but that's another story entirely) path. If a path is moving in a circular (for simplicity's sake) path, it is constantly changing direction. From Newton's first law, we know that, in order to oppose or change uniform motion (motion in a straight line), a force must be present in order to cause acceleration. The force required to cause this acceleration is known as a centripetal force (center-seeking) force, which begets the centripetal acceleration required for curved motion. The difference between centripetal acceleration and general linear acceleration is that centripetal acceleration is always perpendicular to the direction of the vector representing velocity at any given moment. tl;dr: for a projectile moving in a north-bound direction, in order to curve the projectile for t seconds, keep the y-velocity constant and apply either a positive or negative x-directed acceleration for t seconds