0 Favourites

How do I move a sprite going up with constant speed?

  • How do I move a sprite going up with constant speed?

    I tried using the bullet behavior, setting it at negative gravity, but it seems the speed is not constant. Any idea guys on how to solve this?

    thanks in advance

  • Bullet behavior will make an object travel in one direction at constant speed unless you add acceleration, gravity or other movement to it.

    You can just set your object's angle to -90 and some constant speed value you want into "speed" value of bulleet behavior, and that should do the trick.

    If you need more assistance, feel free to ask.

  • Bullet behavior will make an object travel in one direction at constant speed unless you add acceleration, gravity or other movement to it.

    You can just set your object's angle to -90 and some constant speed value you want into "speed" value of bulleet behavior, and that should do the trick.

    If you need more assistance, feel free to ask.

    Bout the -90 angle where do I put this value, the parameter to set angle on the bullet behavior can only be set to YES or NO.

  • When you added a behavior, all related parameters of such behavior will be listed on the left panel. Left click on your sprite that has bullet behavior and look on your left panel. Scroll around a bit. You should see those parameters.

    I am on mobile right now so I cant snapshot this for better clarification. But I would rather advise you to start with basic beginner tutorial first before anything else. See tutorial section and go step by step with those.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • With so much functions in C2, I guess it would take me a bit more time to learn C2. I've been thru those basic tutorials. What I did was, after adding the bullet behavior, I went to the event sheet and set this parameters:

    SYSTEM>EVERY TICK>SPRITE>SET ANGLE TO -90 DEGREES

    It did work, it moves upward, it has the constant speed,, but seems its moving sideways (the right side is the one moving upward, like being rotated counter clockwise -90 ). What I want to happen is the head or top of the object the one moving upward. I guess I'm missing another parameter setting.

  • if you want your sprite to just move up, you don't even have to use the bullet behavior.

    In the event sheet create a new event and add every tick as a condition and for an action (for the object you want to move) choose set Y and write the following expression: self.Y - (any value) * dt

    It should look like this:

    Every tick---> Object | set Y to self.Y - (any value) * dt

    This means that |every frame | your object will look at its current Y position (self.Y) | and it will subtract (move up) some value of pixels (the any value that you will set) |, which by using delta time (dt) you are making sure it will stay the same per second -no-matter the frame rate of the device that the game will be played.

  • Also keroberos is telling about this:

  • if you want your sprite to just move up, you don't even have to use the bullet behavior.

    In the event sheet create a new event and add every tick as a condition and for an action (for the object you want to move) choose set Y and write the following expression: self.Y - (any value) * dt

    It should look like this:

    Every tick---> Object | set Y to self.Y - (any value) * dt

    This means that |every frame | your object will look at its current Y position (self.Y) | and it will subtract (move up) some value of pixels (the any value that you will set) |, which by using delta time (dt) you are making sure it will stay the same per second -no-matter the frame rate of the device that the game will be played.

    Finally got it working.

    thank you so much eli0s for your help, there are so much you can do with C2 on how or what approach you want your object to do, for beginners like me, learning stuff like this from C2 masters like you, would educate me more quiker on C2.

    thanks again, also to keroberos & katzin as well

  • I am sooooo far from being a master that is embarrassing... But you're welcome!

  • I am sooooo far from being a master that is embarrassing... But you're welcome!

    Hey eli0s,

    One last question.

    Is it possible or advisable to set the parameter of pixel per second with a half value in bullet behavior or on the set X or Y actions dt, say for example 51pps deviding it by 2 so it will be 25.5

    Will this cause any problem with your game when exporting to mobile?

  • This wont cause any problem.

  • I have no experience with mobile and this is a very technical question for my understanding on how computers calculate internally.

    That being said, it is certainly possible and I don't believe there will be any difference performance wise. Construct calculates with float numbers so the .5 wont "confuse" it at all.

    The only thing that comes to my mind that is related to "performance" is the pixel rounding. If for some reason in your project settings you have the pixel rounding to on, then perhaps every now and then this .5 value will be round up (or down) and that might cause a 1 pixel jump which may be noticeable.

    • EDIT- That doesn't seem to affect performance neither. Check the following example -input decimal values to test CPU usage.

    http://www.eli0s.com/Tests/FloatDT.capx

  • I have no experience with mobile and this is a very technical question for my understanding on how computers calculate internally.

    That being said, it is certainly possible and I don't believe there will be any difference performance wise. Construct calculates with float numbers so the .5 wont "confuse" it at all.

    The only thing that comes to my mind that is related to "performance" is the pixel rounding. If for some reason in your project settings you have the pixel rounding to on, then perhaps every now and then this .5 value will be round up (or down) and that might cause a 1 pixel jump which may be noticeable.

    -EDIT- That doesn't seem to affect performance neither. Check the following example -input decimal values to test CPU usage.

    You're absolutely right eli0s, This is a very technical question. I've been having second thoughts if I'll use a .5 value to my project parameters. I'm trying to balance or syncing together 200 moving objects, 100 on the -x and 100 on the -y angle meeting together at one point. So far in my experiment its running fine, like I said could this pose any problem later? I guess the only thing to find out is to test test test your game on multiple devices. Thank you again eli0s, for your views on this subject and your sample capx. Also to keroberos............

  • Yes, the best practice will be to test again and again on your target devices. But, just like keroberos said, the decimal value doesn't seem to affect performance in any practical way.

    Anyway you're welcome

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