Page 1 of 1

how do i pick up and throw objects

PostPosted: Sun Oct 16, 2011 4:53 pm
by pikapika
hi im making a platform game an im wondering how to make it so that when you press a certain key only when your actor is standing on top of a certain object, you can pick up the object and by releasing the key throw the object at the enemy.
please post an answer in the box below

Re: how do i pick up and throw objects

PostPosted: Sun Oct 16, 2011 5:33 pm
by EvanBlack
Well first you need to check if you are colliding with the top of the actor, checking if player y + playerheight/2 < object y - objectheight/2, on keydown of specific key. Then change animation to pick up object, turn off collision, move object up above player, so the player is holding it.

Press key down, change animation to throw animation, move change object xvelocity, yvelocity, and have it constantly degrade over time or until collision with enemy. Change animation of enemy, destroy object.

if you want you player to move while holding the object you have to lock the x and y axis to the player using a pointer reference. Check out this page for details on using pointers to get x and y of another actor and reference it to a different actor : viewtopic.php?f=1&t=11162

Re: how do i pick up and throw objects

PostPosted: Wed Oct 19, 2011 5:46 pm
by pikapika
so what am i supposed to do to pick up and through objects in the game

Re: how do i pick up and throw objects

PostPosted: Sat Nov 12, 2011 9:45 pm
by skatermichael
ok so what i do is create a whole other actor called like "playerbox" with an animation of a player holding a box...
put that actor off screen.now with your player on collision of like a box destroy box create actor playerbox then destroy actor player....
now on playerbox actor key down say space create actor box destroy playerbox and create player...nowon box create actor script editor put somthing like this...you can tinker with the numbers to get what you need.
Code: Select all
xvelocity = xvelocity + 4//add anynumber you need here
yvelocity = yvelocity + 2//tinker with the number

and then on box collison of the ground destroy actor box.

i think this would be correct just correct me if this is wrong.