Very unfair bug in classic

For questions about using Classic.

Post » Wed Nov 19, 2014 10:01 pm

Step 1:
Create an sprite and give any behaviour that allows movement (for example, platform behaviour)

Step 2:
Create an sprite for an enemy, with some particulary easy to see animation, for example, an arrow.

Step 3:
Insert this code

"if enemy.x > player.x {set enemy.angle=180;} else { set enemy.angle=0;}"

Step 4:
In the layout, Ctrl+MouseLeftButton to make a copy of various enemies.

then run the cap and observe that not all the enemies turn around, some of them wait until tle player moves his X to the greates or lowest position. So, some of them turn around some of the other doesn´t....nosense.

This makes coding an enemy AI really difficult.

But you can make this works by inserting "for each enemy" condition, however this only works in this case, when you have private variables and the number of the sprites is big, you cannot use "for each" condition, for other reasons, because its not supose to work like that....so there is no way to clearly separate the behaviour of several enemies of the same object
B
6
S
1
Posts: 33
Reputation: 468

Post » Wed Nov 19, 2014 10:13 pm

How about overlap at offset?
Image ImageImage
B
170
S
50
G
178
Posts: 8,378
Reputation: 112,925

Post » Wed Nov 19, 2014 10:30 pm

You can just check this in another post of mine, there is a cap in which you can see how it works.
Overlaping at offset its for collisions, Im talking about private variables bugs
B
6
S
1
Posts: 33
Reputation: 468

Post » Wed Nov 19, 2014 10:58 pm

Not sure, as I am not a user of classic, but maybe there is no picking involved in the expression you are writing (ennemy.x will be the x of one ennemy, probably the first created), the for each actually force it to do this work for each ennemy individually.

But if you have a way of do a simple picking event, that would work from my understanding.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Nov 19, 2014 11:03 pm

Thats how picking works.
If you want all the enemies to turn use either a global variable, or a function.
Image ImageImage
B
170
S
50
G
178
Posts: 8,378
Reputation: 112,925

Post » Wed Nov 19, 2014 11:56 pm

I´m not sure why my game is not working properly then...just one enemy, does exactly what it has to, if I added more enemies they get odd
B
6
S
1
Posts: 33
Reputation: 468

Post » Thu Nov 20, 2014 1:04 am

Maybe this will work.

1.) go to enemy character

2.) go to "pick by comparison"

3.) insert distance formula into pick by comparison

value 1: distance( enemy.X, enemy.Y, player.X, player.Y)

comparison: whatever you choose

value 2: whatever you choose

4.) create sub event under first event

5.) go to enemy character

6.) "compare x position"

comparison: greater than Set angle to 180
x coordinate: player.x

7.) set angle to 180

8.) create another sub event

go to enemy

go to compare x position

comparison: less than Set angle to 0
x coordinate: player.X

9.) set angle to 0
B
10
S
3
G
1
Posts: 103
Reputation: 1,390

Post » Thu Nov 20, 2014 1:13 am

Yes that´s work, but would you mind to chek the post "EnemyAI" and see what is happening there when you have free time? By pressing SPACE you can spawn more enemies. Spend a few minutes lookig how one enemy behave, because that´s perfect behaviour and then observe 4 spawned enemies...that is exactly what I say
B
6
S
1
Posts: 33
Reputation: 468

Post » Thu Nov 20, 2014 1:14 am

Code should look like this

event 1: enemy:Pick by distance(enemy.X, enemy.Y, player.X, player.Y)
sub event 2: enemy: x greater than player x ----------------------------------- set angle to 180
sub event 3: enemy: x less than player x -------------------------------------- set angle to 0
B
10
S
3
G
1
Posts: 103
Reputation: 1,390

Post » Thu Nov 20, 2014 1:24 am

Works
B
6
S
1
Posts: 33
Reputation: 468


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: AllanR and 2 guests