How do I set an sprites angle to the angle of motion

0 favourites
  • 5 posts
From the Asset Store
Complete the collection by purchasing Motion Universe Pt. 2
  • Hi everyone,

    i have a simple problem which i cant figure out my self.

    i have a sprite which is moving and several other objects are applying a force to it:

    [attachment=0:1lfyfljb][/attachment:1lfyfljb]

    so far it works very well, but the objects stays at the same angle, how do i get the object to rotate to the current angle of movement to make it look better?

    the object has family bullets has the solid and the physics behavior. ive tryed to add the custom movement behavior and set angle to self.CustomMovement.MovingAngle but it doesnt change anything

    any suggestions?

    regards patrick

  • If the object you want to rotate uses car motion, the behaviour has the expression VectorX and VectorY, which give the movement of the object in each of these axis i.e. it splits the current movement into its perpendicular components. The angle of movement can then be calculated. Taking 0 degrees as the positive x axis, the direction of movement equals:

    if x > 0 & y > 0 :

    a = arctan(VecX/VecY)

    if x < 0 & y > 0 :

    a = 180 + arctan(VecX/VecY)

    if x < 0 & y < 0 :

    a = 180 + arctan(VecX/VecY)

    if x > 0 & y < 0 :

    a = 360 + arctan(VecX/VecY)

    There may not be VectorX and VectorY values for other behavious. You could calculate them basically by storing the last position of the object and comparing it with the new version and finding the difference in x and y. This method may make the rotation rough so you may have to use some interpolation methods to make it smoother.

  • hi, thank you very much vor your answer, no it doenst use that movement, its just applying forces

    well maybe i can figure out another way or rotate the angle to the greatest force..

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • okey, with the help of briggybrosive found a solution, looks pretty nice now

    for those who are interested here it is: i gave my bullet family some instance variables, fill them first time when the oject is spawned and then update them constandly:[attachment=0:vh0qz9av][/attachment:vh0qz9av]

    regards

    Patrick

  • Glad I could help

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)