Home Game Development physics – Change sprite angle on sloping ground

physics – Change sprite angle on sloping ground

0
physics – Change sprite angle on sloping ground

[ad_1]

I have a problem here with GameMaker built-in physics environment.My player is designed to be on a skateboard. I want my player to rotate its sprite, according to the kind of fixture(up or down slopes) he is moving on.I’ve tried everything i could and everything i could find, but it didn’t help me much, because the object is rotating in a very strange way.I enabled some flags to see the mask. Also, I’ve been studying vector algebra and i know it the angle between vector x speed and vector y speed should be the direction. Please help. Here’s what i have so far:

1 object which is the player
Information about object: obj_Player
Sprite: sprite7
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_Static_Parent
Children:
Mask:
Physics
Start Awake: true
Is Kinematic: false
Is Sensor: false
Density: 0.5
Restitution: 0.1
Group: 0
Linear Damping: 0
Angular Damping: 0
Friction: 0.2
Shape: Polygon
Points:
(76, 52)
(76, 60)
(0, 56)
(0, 52)
Create Event:
execute code:

///Initialize the tires
var half = sprite_width / 2;
var halfy = sprite_height / 2;
var tire = instance_create(x-half+12,y+halfy,obj_Wheel);
physics_joint_revolute_create(id,tire,tire.x,tire.y,0,0,0,0,0,0,false);
var tire = instance_create(x+half+12,y+halfy,obj_Wheel);
physics_joint_revolute_create(id,tire,tire.x,tire.y,0,0,0,0,0,0,false);

Step Event:
execute code:

//Code
facing = -point_direction(0, 0, phy_speed_x, phy_speed_y);
phy_fixed_rotation = true;
phy_rotation = facing;

//Move him
if(keyboard_check(vk_space)) {
physics_apply_impulse(x,y,0,-100);
}
if mouse_check_button(mb_left)
{
phy_position_x = mouse_x;
phy_position_y = mouse_y;
}

Information about object: obj_Wheel
Sprite: spr_Wheel
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_Static_Parent
Children:
Mask:
Physics
Start Awake: true
Is Kinematic: false
Is Sensor: false
Density: 0.05
Restitution: 0.1
Group: 0
Linear Damping: 0.1
Angular Damping: 0.1
Friction: 30
Shape: Circle
Points:
(8, 8)
(8, 8)
Create Event:
execute code:
Keyboard Event for Key:
execute code:
physics_apply_torque(-100);

Keyboard Event for Key:
execute code:
physics_apply_torque(100);

And here is the result:
https://i.stack.imgur.com/sn1qh.gif

[ad_2]