Range with Bullet Behaviour

For questions about using Classic.

Post » Sat May 09, 2009 1:44 pm

2 questions about an object with Bullet Behaviour:
- in debug-mode the amount of pixels traveled can be seen. Can I use this information in events?
(For example: after traveling 200 pixels, set speed to 20)

- is there a known bug with exceeding range?
It completely ignores the "on exceeding range"-event.
Am I doing this wrong?

(1 condition, 2 actions)
Sprite A: On collision with Sprite B
> Sprite A: set bullet range to 210
> Sprite A: 'private variable' to 1

(2 conditions, 1 action)
Sprite A: 'private variable' equal to 1
On exceeded range
> Sprite A: set speed to 2
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Sat May 09, 2009 1:50 pm

Object[Bullet].Travelled contains how far it's gone.

On exceeded range should be there first condition in the second event.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Sat May 09, 2009 1:55 pm

Yeah, the 'travelled' expression in the bullet behavior retrieves its distance travelled.

The range exceeded thing might be a bug, can you reproduce it in a new .cap?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Sat May 09, 2009 8:40 pm

Bug reported (artifact number 2789509) about influencing/changing the range (at runtime), with added cap.

[quote="Rich":92y9u1b5]Object[Bullet].Travelled contains how far it's gone.
[/quote:92y9u1b5]

Thanks, that's what I was looking for.
Although one question arised quickly:

1 object is making distance (bullet behaviour).
After every set distance, carry out an action (for example, change direction).

Object[Bullet].Travelled > 50
>Set angle to Object.Angle - 40
Result: keeps spinning.

I thought, that's logical, since the angle is changed, but it's still making distance, so it stays above 50.
But if I change the "> 50" to "= 50", nothing happens.
Is that normal?
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Sat May 09, 2009 9:04 pm

Since the object is moving via timedelta, it's skipping over 50. So if it's moving 100 pixels per second, then it moves 100*timedelta pixels, which results in distance travelled numbers like 50.095lotsmorenumbers. Using distance travelled = 50 would only work if you knew at some point it would equal that, like moving 10 pixels per frame, but then the speed wouldn't be consistent on all computers.

What you want to do is use the trigger once while true condition after the distance travelled is greater than 50 condition.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Sat May 09, 2009 9:26 pm

[quote="rogerty":iharuta6]Object[Bullet].Travelled > 50
>Set angle to Object.Angle - 40
Result: keeps spinning.[/quote:iharuta6]
Add the 'trigger once' condition below the comparison. The bullet will still have travelled more than 50 pixels every tick after it first reaches 50 pixels, so it keeps running the event every tick.

As Arima said, you have to be careful making direct comparisons to numbers like that. If the distance travelled was 49 one tick then 51 the next, your event never runs. Even if it has travelled 50.000001 pixels one tick, the event would not run.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests