GameMaker Physics: lengthdir question

L

Larf

Guest
I started to make a game using physics, and I have a question. I have my topdown game with a character that has a weapon, the weapon's sprite's x and y being the same as the caracter x and y. And I want the weapon to spin following the right joystick's spin (around the character), I think I want to use torque, because I want the weapon to be able to push things, but I have no idea of how to have the weapon spin like that, my problem being that I don't know how to tell with code if the weapon has to spin clockwise or anticlockwise, maybe there is a even simpler way? how would you do it?

I'm sorry if my problem is hard to understand, but... I need help.
Thanks!
 
R

Raphael Caloz

Guest
This should do the trick :
var dir = joystick_direction(2);
var distanceFromPlayer = 10;//Change this to the dist. you want the weapon from the player

obj_weapon.image_angle = dir;
obj_weapon.x = obj_player.x + lengthdir_x(distanceFromPlayer, dir);
obj_weapon.y = obj_player.y + lengthdir_y(distanceFromPlayer, dir);

You can simplify the code depending in which object you execute it be removing certain object references (obj_weapon,etc). Good Luck!
 

Jezla

Member
This should do the trick :
var dir = joystick_direction(2);
var distanceFromPlayer = 10;//Change this to the dist. you want the weapon from the player

obj_weapon.image_angle = dir;
obj_weapon.x = obj_player.x + lengthdir_x(distanceFromPlayer, dir);
obj_weapon.y = obj_player.y + lengthdir_y(distanceFromPlayer, dir);

You can simplify the code depending in which object you execute it be removing certain object references (obj_weapon,etc). Good Luck!
That won't work with physics enabled, not if both player and gun are physics objects (which they should be). To make the gun respond to the joystick, then apply an angular impulse rather than torque.
 
Top