How do I limit how far a sprite can go?

0 favourites
  • 7 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Hello!

    I want to make some sort of shooter game with mobile support in C3.

    The main player sprite has a bullet behavior and its speed is two X the distance between the joystick sprite and its initial location. The joystick sprite has a drag-drop behavior and when it isn't being dragged, it goes back to its initial location. The player's angle is also calculated by using "angle(x, y, joystick.x, joystick.y)"

    However the user can move the joystick all the way to the top-right which will make the player move way too fast, so i want to know how to stop the joystick sprite from moving more than 128 pixels from its initial location.

    Thanks in advance.

    PS: here is the project if you need to try it out:

    drive.google.com/open

  • Your cloud folder seems to be empty? Anyway, here is an example i made. Try to understand and if there is anything unclear feel free to ask:

    1drv.ms/u/s!Ap_-qxoGKbDcg2sr7MfPtOhYVwGu

  • Thank you! You got exactly what I wanted but I don't seem to understand how this works

    If you can explain a bit I would be very thankful

    PS: I think this link works, try it if you need to:

    drive.google.com/open

  • Can you say what exactly you do not understand or is everything unclear?

  • I don't know what is touch index and there is this event that I right-clicked and copied as text:

    + Touch: Has touch Stick.TouchIndex

    + Stick: TouchIndex > -1

    -> Stick: Set position to StickArea (image point 0)

    -> Stick: Move min(distance(StickArea.X, StickArea.Y, Touch.X(1), Touch.Y(1)), (StickArea.Width - Stick.Width) ÷ 2) pixels at angle angle(StickArea.X, StickArea.Y, Touch.X(1), Touch.Y(1))

    I need help understanding this plz

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need TouchIndex to distinguish between multiple touches. For example when you move your character with one finger and shoot with another finger your character will still move when you end the touch for shooting and not for moving.

    Because the TouchIndex can be 0 and greater i choosed -1 to check if the Stick is in use or not.

    min(a,b,c,d...) always gives back the smallest number. So when the finger did not reach the edge of the StickArea, the distance between the center of the StickArea and the finger is smaller then the distance between the center and the edge of the StickArea. If the finger exceeds the StickArea, the maximum distance the Stick can move is to the edge of the StickArea and this is calculatet by (StickArea.Width-Stick.Width)/2.

  • That explains a lot

    Thank you so much!

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