Applying vector X to sprite with max speed of 35

Get help using Construct 2

Post » Sun Sep 09, 2012 3:36 am

More questions :)

This seems like it should be a really simple task, but I can't quite get my head around it. I am shooting a bullet at the enemy (with platform behaviour) and on collision I am applying 2000 to Vector X (to simulate the enemy being bumped backwards). At first I found this wasn't working at all, but then I noticed that Max Speed was set to 35. Once I set the max speed to 350 the enemy would be bumped back a much better looking distance and continue on their path.

The problem is, I don't want my enemy at the max speed of 350 :)

If I try to set the speed to 350, change the vector x to 2000, then change back to 35, it all happens too fast and the enemy does not move. If I try to set some sort of wait event, this could have unpredictable results.

What would be a smart way of saying "Take the enemies max speed, change it to 350, apply a vector x, then when [?], change back to 35". The tricky part is the [?]. I don't quite know how to determine when to switch back to the max speed of 35. As I said, it seems simple but got confusing fast
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sun Sep 09, 2012 10:26 am

Hey boolean.

Just thinking out loud.

Maybe if you made your speed a variable instead, like :

every tick -> Set Player Speed = Player.SpeedVariable.

Then you could add (or subtract) speed from the variable on the fly easily. As for the how to get back to the normal speed you could do a couple of things, you could have a timer that when hits a certain point (like 1 second) sets the speed back to normal. You could also set it back to normal when they hit the ground or when they have gone a certain distance. GenkiGenga2012-09-09 10:27:22
ImageImage
B
73
S
16
G
6
Posts: 1,038
Reputation: 10,473

Post » Sun Sep 09, 2012 10:29 pm

[QUOTE=GenkiGenga] You could also set it back to normal when they hit the ground or when they have gone a certain distance. [/QUOTE]

I was thinking of something similar to this today. I'm wondering if you could set the max speed to 350, apply the x vector, then maybe do a "if movement speed is < 10, set to max speed 35'. That might work.

I'll give it a try and see how it goes.
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sun Sep 09, 2012 10:45 pm

What's wrong with changing the max speed and setting it back after a 'wait' action? What's unpredictable about that?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Sun Sep 09, 2012 10:55 pm

It's that I don't know how long to wait for. If I have an enemy that is supposed to be heavy, they might only get bumped back a few pixels, but another regular enemy might be bumped back many pixels. In this case, do I set the wait time to be low or high? I could make it an instance variable, but it's going to be hard to test the exact amount of time to wait for every enemy.

This also gets tricky if another event occurs like the enemy hits some scenery. He gets pushed back, but instead of travelling the full distance (a 1.5 second wait), he hits some scenery and, with the event now taking place at 0.5 seconds, rockets forward for one second while the wait timer ticks down.

I'm playing about with GenkiGenga's suggestion right now and so far it seems to be working well. I'm going to test it a little more then I'll post a screenshot of the event sheet.
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sun Sep 09, 2012 11:05 pm

So as mentioned I tried GenkiGenga's suggestion, using speed instead of distance, and it seems to work pretty well. I won't upload the whole capx as this seems like a pretty simple exercise, but here are the events if anyone is interested:


(Oddly, "speed < 1" works, but the "On Stop" event does not.)

Is there any other ways anyone might be aware of?
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sun Sep 09, 2012 11:28 pm

if your enemy always go left you can do something like:

You set the maximum speed to 800 or higher in properties
[code]Bullet: On collision with enemy
-> enemy: Set Platform vector X to 800
Every tick
-> enemy: Simulate Platform pressing Left
-> enemy: Set Platform vector X to clamp(self.platform.vectorX,-15,800)[/code]

(setting the vector X to something greater than 800 is useless since you'll just be clamped to maximum speed)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Sep 09, 2012 11:38 pm

Oh very sneaky! Ha, that would certainly work
B
24
S
4
G
1
Posts: 244
Reputation: 3,462


Return to How do I....?

Who is online

Users browsing this forum: CavalierBubble, Evanetot and 25 guests