point object in two directions

J

JON213

Guest
I would like to have this arm object to point in 2 directions. One end pointing to the mouse and the other the to the other half of the arm. Currently, I have the top half of the arm pointing to the bottom half and the bottom half pointing at the mouse. However, if I shoot at the ground recoil causes the top half to go haywire and look like the image below.
upload_2019-6-23_11-56-29.png
Here is what I use for the top half
Code:
image_angle=point_direction(x,y,obj_Arm.x,obj_Arm.y);
And here is what I use for the bottom half
Code:
image_angle = point_direction(x,y,mouse_x,mouse_y)
 
This is a fairly basic example, but it's how I'd look at something like this:

set a point as the "shoulder"

Code:
angle = point_direction(shoulder_x, shoulder_y, mouse_x, mouse_y);
new_angle = angle - 90; // This is fixed for now, but you could find ways to make it more responsive (the arm is always going to be rigid, as is)

top_arm.x = shoulder_x; // top arm origin
top_arm.y = shoulder_y // top arm origin

top_arm.image_angle = new_angle;

bot_arm.x = shoulder_x + lengthdir_x(top arm length, new_angle) // top arm length is just pseudo code - you will know what this length should be
bot_arm.y = shoulder_y + lengthdir_y(top arm length, new_angle)

bot_arm.image_angle = point_direction(bot_arm.x, bot_arm.y, mouse_x, mouse_y);
In the image below the red dots on the right side are the origin points of the arm parts, and they are two separate objects. The image furthest right is what I mean about the arm being rigid, due to having a fixed angle of 90 degrees being subtracted from the angle of the "shoulder" to the mouse. It works, but could be expanded upon.

arm.png
 
Last edited:
J

JON213

Guest
Thank you! Could you please repost the image because I get an error saying requested attachment cannot be found.
Doesn't matter I can see the image now.
 
Last edited by a moderator:
Top