"physics_apply_force" problem <SOLVED>

Discussion in 'Programming' started by HayManMarc, Apr 17, 2019 at 7:09 PM.

  1. HayManMarc

    HayManMarc Member

    Joined:
    Jun 21, 2016
    Posts:
    840
    I'm playing around with physics and trying to get an object to move straight ahead. I'm using this bit of code:

    Code:
    var forward_x = lengthdir_x(8000, -phy_rotation);
    var forward_y = lengthdir_y(8000, -phy_rotation);
    physics_apply_force(x, y, forward_x, forward_y);
    
    It moves the object, but causes it to turn slightly to the left. How do I make it so it moves straight forward?

    For context, the object is a car viewed from the top.

    Note: I'm hoping for a simple solution, as true realism (perfect driving sim) is NOT the goal.
     
  2. JML

    JML Wabbajackalope

    Joined:
    Jun 22, 2016
    Posts:
    337
    their is a good change that the origin of the sprite and the center of mass are not aligned, try using this and see what happens

    physics_apply_force(phy_com_x, phy_com_y, forward_x, forward_y);
     
    HayManMarc likes this.
  3. HayManMarc

    HayManMarc Member

    Joined:
    Jun 21, 2016
    Posts:
    840
    I fixed it by adjusting the points in the collision shape. They were not very exact. (All I had to do was ask a question on the forum for the answer to dawn on me. Doh!)
    Thanks for the reply, @JML. That may come in handy later. *thumbs up*

    (actually, using "phy_com_x/y" may have been easier. lol)
     
  4. JML

    JML Wabbajackalope

    Joined:
    Jun 22, 2016
    Posts:
    337

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