(solved) Acceleration - Max Speed - Deceleration

Get help using Construct 2

Post » Wed Feb 08, 2012 4:42 pm

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

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.   Schoening2012-02-09 18:38:13
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Wed Feb 08, 2012 5:56 pm

I'm not sure what your question is, so in doubt I'll reference you to the how do I FAQ and precisely this :
[quote]Several RTS mechanics (camera movement, selecting units, etc...) - LINK[/quote]

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Wed Feb 08, 2012 7:49 pm

OK ill do that.

B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Wed Feb 08, 2012 8:02 pm

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.
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Wed Feb 08, 2012 8:39 pm

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
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Wed Feb 08, 2012 10:11 pm

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
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.Schoening2012-02-08 22:17:28
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Wed Feb 08, 2012 11:02 pm

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
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Wed Feb 08, 2012 11:08 pm

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

Gives me Syntax Error
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Wed Feb 08, 2012 11:12 pm

Ok solved.. just added another expression.

Speed Equal or More than 100    Set speed = 100
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Wed Feb 08, 2012 11:30 pm

I think you misread, its supposed to be

min(distance(x, y, Sprite.X, Sprite.Y)/2, 100)
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests