1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

[Solved] Rotation physics throwing off controls

Discussion in 'Programming' started by Algae12185, Dec 3, 2017.

  1. Algae12185

    Algae12185 Member

    Joined:
    Jun 5, 2017
    Posts:
    7
    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
    
     
  2. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    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?
     
  3. Algae12185

    Algae12185 Member

    Joined:
    Jun 5, 2017
    Posts:
    7
    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.
     
  4. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    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
     
  5. Algae12185

    Algae12185 Member

    Joined:
    Jun 5, 2017
    Posts:
    7
    Thanks that helps. Not sure how I over-looked that. I was doing a work-around but this will make it better.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice