How to make the movement only diagonal in 4 directions?

Order by:
Duplicate Topic
Posts
Views
Last Post
Not favoritedFavorited Favorited 1 favourites
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • View from top

    How to make the movement only diagonal in 4 directions? The direction of movement is 45 degrees

    Bullet, set angle - off

    Solid - on

    On collision it turns out that the angle changes not 45 degrees

    ________________________________________

    It needs to be like in the picture below

  • You can round the angle to 45 degrees after the collision.

    Set angle to round(((angle+360)%360)/45)*45

  • You can round the angle to 45 degrees after the collision.

    Set angle to round(((angle+360)%360)/45)*45

    How do I understand what angle value to put in the brackets? Or do I need to use some global variable?

  • You can round the angle to 45 degrees after the collision.

    Set angle to round(((angle+360)%360)/45)*45

    I haven't been able to do this for two days, I've done everything else. If it is not difficult you can make me a project and send it to me

  • Change angle to sprite.angle or whatever name you gave the object.

    Or since you are using the bullet behavior with “set angle” to no, you’d want to use the action:

    “Bullet: set angle of motion” and use dop’s formula with

    round(((sprite.bullet.angleOfMotion+360)%360)/45)*45

  • Change angle to sprite.angle or whatever name you gave the object.

    Or since you are using the bullet behavior with “set angle” to no, you’d want to use the action:

    “Bullet: set angle of motion” and use dop’s formula with

    round(((sprite.bullet.angleOfMotion+360)%360)/45)*45

    doesn't work

    Subscribe to Construct videos now
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So it doesn't work because it can go vertical or horizontal sometimes? We can modify the formula further to only have angles at 45 degrees. Probably this:

    round(((sprite.bullet.angleOfMotion+45+360)%360)/90)*90-45

    For a single object you could also basically do the motion manually with two variables for the x and y velocity, then use overlapping at offset to see when to bounce. Logic would roughly be:

    start of layout
    -- sprite: set vx to 1
    -- sprite: set vy to 1
    
    sprite: overlaps wall at offset sprite.vx, 0
    -- sprite: set vx to -self.vx
    
    sprite: overlaps wall at offset 0, sprite.vy
    -- sprite: set vy to -self.vy
    
    every tick:
    -- sprite: set position to self.x+self.vx, self.y+self.vy

    However that doesn't work well if you have multiple moving objects that you want to bonce off each other.

    For a more deluxe and precise way you could move overlapping objects out of each other and calculate the collision normal at the same time to bounce off of. Construct doesn't have a built in way to do that so here is a way to do it between axis aligned boxes by utilizing an algorithm called the Separating Axis Theorem.

    dropbox.com/scl/fi/ac5ihr1qp0xpmoj7mtskh/perfect_bounce_w_sat_collision.capx

  • If you want a mega-ultra-hyper-super simple and easy solution, use the Physics Behavior and this single event:

    Then, you will get this result:

    Subscribe to Construct videos now

    Here you have the .C3P sample project file: fileport.io/4nfWCb2NdtnN

  • If you want a mega-ultra-hyper-super simple and easy solution, use the Physics Behavior and this single event:

    I was skeptical, but it really works! I guess Physics collision calculations are more precise than those in Bullet behavior.

    But still, after 10 minutes or so this happened:

  • dop2000 That will never happen again if you use this simple code:

    Here is the new .C3P sample project file: fileport.io/rkDSu2KFmmTq

  • I'm happy! Thank you all so much )

  • dop2000 That will never happen again if you use this simple code:

    There is a nuance. When there are many objects (in my case 20)

    The angle of motion and speed changes

    Subscribe to Construct videos now
  • For a more deluxe and precise way you could move overlapping objects out of each other and calculate the collision normal at the same time to bounce off of. Construct doesn't have a built in way to do that so here is a way to do it between axis aligned boxes by utilizing an algorithm called the Separating Axis Theorem.

    https://www.dropbox.com/scl/fi/ac5ihr1qp0xpmoj7mtskh/perfect_bounce_w_sat_collision.capx?rlkey=79m2711gc929l9mdm9hjier6n&st=xgf1cgo4

    I take it that for multiple sprites this won't work. I can't figure it out

  • There is a nuance. When there are many objects (in my case 20)

    The angle of motion and speed changes

    I didn't know you'd need more than two objets. I'll think of another way to do it for many objets.

  • > There is a nuance. When there are many objects (in my case 20)

    > The angle of motion and speed changes

    I didn't know you'd need more than two objets. I'll think of another way to do it for many objets.

    I'll look forward to it

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