### Author Topic: Throwing an Object and having it rise and fall  (Read 1173 times)

#### emospacemonkey

• Guest
##### Throwing an Object and having it rise and fall
« on: Sun, Jan 24, 2010 »
Hi,

I want my Player to be able to throw an item at an enemy. I do not want this item to move simply horizontal. It should move on up and then horiztonal and then fall down.

Is the best way of doing this to assign this "bullet" gravity e.g. acceleration.y ?

Anyhow I'll give it a go, if I hear any other suggestions let me know

Regards
EmoSpaceMonkey

#### photonstorm

• Key Contributor
• Posts: 1502
• Karma: +1/-0
##### Re: Throwing an Object and having it rise and fall
« Reply #1 on: Sun, Jan 24, 2010 »
I think you're on the right track already - give it a negative acceleration, and in the bullets update function check to see if the Y velocity has hit the "peak" of your arc, and then reverse the acceleration to be positive.
http://www.photonstorm.com

"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

#### Richard Kain

• Active Member
• Posts: 231
• Karma: +0/-0
##### Re: Throwing an Object and having it rise and fall
« Reply #2 on: Mon, Jan 25, 2010 »
The easiest way is to set an initial vertical acceleration, and then set an initial vertical velocity in the opposite direction. For horizontal motion, assign the velocity to whatever you want and have it remain consistent.

Setting the initial acceleration allows you to "simulate" gravity. (the object will by default "fall" in the direction that you set the acceleration) Setting the initial velocity in the opposite direction of the accleration will make your object "arc" as you are describing. It will begin rising, but the setting for the acceleration will take over, and cause it to start falling after it has reached its apex.

#### emospacemonkey

• Guest
##### Re: Throwing an Object and having it rise and fall
« Reply #3 on: Mon, Jan 25, 2010 »
Yes that did it. In the shoot function set the initial acceleration and the initial velocity. The lower the initial velocity the smaller the arc.

Great. Did the job. No my Monkey gets caught in the cage

Stephen