[Solved] Rotation physics throwing off controls

A

Algae12185

Guest
I am making controls by clicking the object, and releasing the mouse elsewhere to move the object in that direction. Everything works fine when I have phy_fixed_rotation = true, but as soon as I add rotation it throws everything WAY off. I understand that with rotation it will throw it off some, but it seems seriously off. What can I do (other than have no rotation) to remove or reduce how much rotation affects the controls?

Code:
//Left Mouse Press
pressx = mouse_x
pressy = mouse_y

//Left Mouse Global Release
xforce = lengthdir_x(point_distance(pressx,pressy,mouse_x,mouse_y),
point_direction(pressx,pressy,mouse_x,mouse_y))*2

yforce = lengthdir_y(point_distance(pressx,pressy,mouse_x,mouse_y),
point_direction(pressx,pressy,mouse_x,mouse_y))*2

if pressx != 0 & pressy != 0
{
 physics_apply_local_force(0,0,xforce,yforce)
}
pressx = 0
pressy = 0
 
H

Halph-Price

Guest
Friction, or make the controls relative to the position of the object, instead of absolute to the object. Not sure I entirely understand fully the question, but I am guessing, you're having an issue with the objecting spinning when it should be SLIDING.

It's sometimes messing with friction and mass that can fix that, and is REALLY the nuance of the physics engine. Those 4 other properties that every object has can change it from kicking a tin can across ice, to smacking an iron weight in mud.

Is the object acting too much like a tin can or more like a spinning top?
 
A

Algae12185

Guest
Let me try to clarify what is happening with an example.

With rotation off I left click the object, move the cursor above the object, and release the left mouse button. The object then has force on it to go up towards where I released the left mouse button. This is what I want to happen.

However, when I turn the rotation on and the object starts to spin (like a top), when I do the same thing as above the object seems to go off in a completely different direction. Instead of going up, it might go down instead.

Ideally I would want the objects to be able to spin so if they collide with each other they would react appropriately with the physics, but as far as controls go I don't want it to interfere. If I do the above example, the object would go upward, regardless if it is spinning or not.

I hope that clarifies.
 
H

Halph-Price

Guest
Let me try to clarify what is happening with an example.

With rotation off I left click the object, move the cursor above the object, and release the left mouse button. The object then has force on it to go up towards where I released the left mouse button. This is what I want to happen.

However, when I turn the rotation on and the object starts to spin (like a top), when I do the same thing as above the object seems to go off in a completely different direction. Instead of going up, it might go down instead.

Ideally I would want the objects to be able to spin so if they collide with each other they would react appropriately with the physics, but as far as controls go I don't want it to interfere. If I do the above example, the object would go upward, regardless if it is spinning or not.

I hope that clarifies.
So that's the force moving on the object relative to it's position

"Another way to use force in the physics world is to apply it locally to an instance. What this means is that the strength and direction of the force are calculated based on the origin (or the position if it has no sprite) of the instance, without taking into consideration the direction or rotation it may have in the game room or physics world. It should be noted that with this function, forces are not applied to the center of mass of the object, but rather at a point relative to the instance and they will not be instantly applied as they are dependant on any other forces that are working on the object (like gravity). This illustration demonstrates how a local force works:"

https://docs.yoyogames.com/source/d...physics/forces/physics_apply_local_force.html

if you use physics_apply_force instead of local force, you won't have that issue obviously.


Sorry for the delay, hope you figured that out before :3
 
A

Algae12185

Guest
Thanks that helps. Not sure how I over-looked that. I was doing a work-around but this will make it better.
 
Top