How do I tilt on touch?

0 favourites
  • 12 posts
From the Asset Store
Surena Touch
$2.50 USD
A wrap from official Touch plugin to export touch/mouse input to other plugins.
  • Hi folks, I managed to make my spaceship to tilt with the keyboard but not with the touch controls.

    I' trying to detect the direction which is moving the spaceship in order trigger the tilt right and left. Can't understand how to detect the direction the ship is moving.

    I should detect if it's moving +x or -x towards it's starting position I believe right?

  • I'm sorry, maybe I'm not very clear on your question, but if you have already set the movement commands, why don't you tilt your spaceship according to the input you receive? Input to the right = tilt to the right etc.

    For your last question, the answer is yes. Every tick you should check the position in the X-axis of the spaceship in the previous tick (which you saved inside a variable). If newPosX > oldPosX then the ship is moving to the right, if newPosX < oldPosX then the ship is moving to the left, if newPosX = oldPosX then the ship is stationary.

    I repeat that however you could simply tilt the ship according to the movement input received (keyboard, controller or touch), without making every tick a check on its position in the X-axis.

  • Hi bro, yes your question make sense. This is why:

    The problem is that the spaceship is moving according to where my finger is. SO I never set really a right or left command.

    Thanks for your answer. I'll try that.

    Edit: could you please provide an example of this?

    "Every tick you should check the position in the X-axis of the spaceship in the previous tick (which you saved inside a variable). If newPosX > oldPosX then the ship is moving to the right, if newPosX < oldPosX then the ship is moving to the left, if newPosX = oldPosX then the ship is stationary."

    I'm not sure how to check the spaceship position and compare it with the previous one.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, I think i managed to do it properly. Can u check please if it's done as u suggested?

    Check of the spaceShip position:

    Hero is the spaceship.

  • This is a simple example to help you understand what I wrote. Theoretically, if the ship moves only during the "Is in touch" event, you can move the control there, instead of in the "Every tick" event.

    I noticed that you use the "Move To" behavior to make the ship move. In your first post you were only asking about the tilt based on the X axis, but in your case, the ship also moves on the Y axis and also changes angle. So you have to adapt the various controls according to your situation (surely you have to insert a control on the Y axis just like you are doing on the X axis).

  • Thanks bro for your example, I'll try that and back to u if needed. Thanks a lot!!!!

  • Can u tell which command are u using in the comparison in the event (x> previousHeroX)

    Edit solution: ok it's COmpare X and Compare Y. Thanks man

  • That's right. You can still use any other event to compare two values, such as "Compare two values" in System.

    Glad I was helpful. Happy programming! ^^

  • Awesome, it's working. Thanks a lot.

    Now It's glitching a little bit I just need to fix few things, I hope to manage to do it alone.

    I'm not sure about how to manage the Y axis as you mentioned before but it makes totally sense so I have to dive into it.

  • Just for the sake of info this is what I came up with thanks to your help Biscotto.

    Now the problem is that the Spaceship si looping the tilt even if the animation is not looping. I believe it's because the ship is constantly changing it's position.

    I should tell the ship that the animation should be executed just once on this first movement to the right.

    My next mission. If you know how to do that, u're more than welcome to help me out :-D

  • The first solution that comes to my mind, is to add a control on the current animation of the object, before assigning it a new animation.

    Example: If you move to the right, and the "right" animation is already present then don't set the "right" animation again.

  • I managed to do the whole tilt.

    Thanks man for your help!

    This is the code for future reference.

    Edit: it's still not perfect but I'll work on it

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