(solved) Acceleration - Max Speed - Deceleration

  • So the SpaceShip game i am working has some basic rts kinda movement.

    Click and Move.

    Added rotation so the ship has to maneuver by rotating in a circle instead of instant changing the direction.

    But it looks horrible <img src="smileys/smiley36.gif" border="0" align="middle" />

    Once the sprite is in the ca. position of the last click it just makes a full break ! Making the driver hit his head in the window!

    I would much rather have it to decelerate once it comes close to the location. So if you click just a few pixels in front of your ship, it would slide to far. Also i want the ship to accelerate until the max speed is reached.

    I could only find some stuff on this for custom movement.

  • I'm not sure what your question is, so in doubt I'll reference you to the how do I FAQ and precisely this :

    everal RTS mechanics (camera movement, selecting units, etc...) - LINK

    If this doesn't help try posting your capx and explaining much in depth what you want to do, what you expect your code to do, what's it doing instead.

  • OK ill do that.

  • Link

    That is a picture of my Script at the moment.

    I want the ship to slow down when getting close to the point.

    I want the ship to keep momentum, and not instantly loose it..

    If you change direction all of the sudden, the ship would still need to decelerate or accelerate.

    And accelerate slowly to a max speed. Bullet seems to keep getting faster and faster.

  • You can make it

    + Every tick

    -> Set bullet speed to distance(x, y, Sprite.X, Sprite.Y)/2

    So if its too far away, its faster, and if its too close, its slower

  • Thats smart ^^ ty :D

    Now i just need to find the max speed limit thing :)

    Edit: I just tried it, It's getting there but not really what i need. I might use the idea for when at a certain distance. But just using the

    distance(x,y,Sprite.X,Sprite.Y)/2) is not working because if i click far away.. it will just speed up <img src="smileys/smiley36.gif" border="0" align="middle" />

    The speed is not supposed to be defined by distance completely. There is a Speed constant for the Ship that only should change when near to approaching destination.

  • So try

    + Every tick

    -> Set bullet speed to min(distance(x, y, Sprite.X, Sprite.Y)/2, 100)

    Where 100 is the max speed

    The expression min(a, b) returns the lowest value of the two, so if distance() gets higher than 100, it gets ignored and the game will use the value of 100 instead

  • distance(x,y,sprite.X,sprite.Y)/2 , 100

    Gives me Syntax Error

  • Ok solved.. just added another expression.

    Speed Equal or More than 100    Set speed = 100

  • I think you misread, its supposed to be

    min(distance(x, y, Sprite.X, Sprite.Y)/2, 100)

  • Ah i see :) Thx yes that works 2 ! Probably faster than 2 or 3 functions.

    Any idea on the acceleration? Instead of Setting the Speed from 0 to 100. Going to accelerate to 100.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry, but no :/

  • No problem ^^

    edit: it is NOT 12:48 am   it is   01:50 am !

  • No problem ^^

    edit: it is NOT 12:48 am   it is   01:50 am !

    lol

  • I figured it out :)

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