How do I make an event every n pixels? (from bullet)

Get help using Construct 2

Post » Thu Oct 27, 2016 9:49 am

Hello,
I would like to make an event that every n pixel a bullet behavior run through. (see capx)
I have global Variable, GridSize, and I would like to make CollisionDetector's position and direction set to Player's direction + GridSize.
In my caps, I need to keep key down to move CollisionDetector, but still not good because no n pixel ticks.

I hope I could explain clearly what I want to do.

Thank you so much for your help

Capx file
B
15
S
4
Posts: 57
Reputation: 1,792

Post » Thu Oct 27, 2016 1:46 pm

You can 'Pin' the collision detector to the player, will that do what you want? Or is this something to do with the movement of the player, you want it to move in grid style?
B
45
S
15
G
73
Posts: 2,019
Reputation: 43,420

Post » Thu Oct 27, 2016 2:25 pm

not sure if I understood correctly but i think that the bullet behaviuor property distancetravelled should help you
B
9
S
4
G
1
Posts: 30
Reputation: 867

Post » Thu Oct 27, 2016 4:32 pm

Moving on a (your) grid + move restrictions.

https://www.dropbox.com/s/g581enxh3nklb ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,472
Reputation: 20,908

Post » Thu Oct 27, 2016 4:46 pm

I made an update, changed everything but movement is super weird. I don't know how to explain so better to check the capx.

Capx
B
15
S
4
Posts: 57
Reputation: 1,792

Post » Thu Oct 27, 2016 6:14 pm

99Instances2Go wrote:Moving on a (your) grid + move restrictions.

https://www.dropbox.com/s/g581enxh3nklb ... .capx?dl=0


Thanks ! Working very well ! Just a question, changing the speed would be set... where ?
B
15
S
4
Posts: 57
Reputation: 1,792

Post » Thu Oct 27, 2016 6:56 pm

On two places.

1/ the time when starting the timer
2/ in the lerp (event 18) ----> lerp(Player.startX,Player.destX,Player.Timer.CurrentTime("go") * 5)

The lerp factor (that Player.Timer.CurrentTime("go")) must count from zero to 1.
Whit the timer counting to 0.2 (in my example) you must multiply the counter with 5. Thats is why 5 is there.

If you start the timer with a time 0.5 it has to be Player.Timer.CurrentTime("go") * 2
If you start the timer with a time 2.0 it has to be Player.Timer.CurrentTime("go") / 2

So in general it is 1 / the timer time.
How less time you give it, how faster it runs. This is already FPS in-depended. NO dt needed.

You see ?

Another thing. This 'set position' in event 20 is very very important. Else (because positions are like 3.333333) the little math errors will stack up, and you will run in the walls. That is also why it is difficult to make a bullet work. A bullet depends on sin and cos, hence numbers like 1.4584984949494949, and the grid is an exact multiply of 32.
B
33
S
18
G
28
Posts: 2,472
Reputation: 20,908

Post » Thu Oct 27, 2016 7:15 pm

Thank you for your time, I really appreciate your explanation :)
Everything is perfect!
B
15
S
4
Posts: 57
Reputation: 1,792


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Casimir, tarek2 and 11 guests