Proper Programming Methodology

Discussion and feedback on Construct 2

Post » Sun Aug 18, 2013 8:38 pm

I've been working on a game for a while, and I'm starting to run into issues with slower performance machines.

I've been trying to use DT everywhere I could, but I believe I may have been programming incorrectly, and I wanted to see what the best approach would be.

Normally what I would do is set an instance variable (#) on an object. I would then set "if instance variable > 0, every 0.1 second, subtract 1 from instance variable". Then, whatever I wanted the sprite to do; attack, jump, etc. I would go "if instance variable = 0", do this and set instance variable to 10.

Now, of course this works on probably all machines. But I'm using this for everything, and I'm afraid it's not a good way to do it. For instance, I have an air dash in my game that sets an instance variable to 4, and subtracts every 0.1 seconds moving 1500*dt pixels every tick. However, the end location doesn't match up when the fps is low (<25), and I can sometimes dash through walls, which is unintended.

I've tried adding dt to the variable and setting when the variable > or equal to X (usually the number of seconds I want it to last), set back to 0, but it still doesn't have the same result everytime.

I'm using this to change enemy attacks, as timers for reloading, damage timers, etc.

So my questions is this: What am I doing wrong, and what should I be doing instead?

B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Sun Aug 18, 2013 8:56 pm

There's no need to add "every 0.1 seconds".
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Sun Aug 18, 2013 9:12 pm

So I should just add every tick?
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Sun Aug 18, 2013 10:00 pm

@MadFactory - forgot to add this!
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Sun Aug 18, 2013 10:28 pm

@ome6a1717 for speed of 1500 pixels/sec for a performance of 10 FPS the sprite will move 1500*0.1=150px (more or less), so if you have problems with missing collision make you sprite bigger than the jump it makes every tick
For the other problem of not stopping every time on the same location, you could store the end position in an instance variable and make the sprite snap to the stored position if it passes or is near the desired position.

Another idea is to use dt to check the performance of the machine so the the final jump to end location look smooother.

P.S. Bullet behavior uses dt to maintain speed on different FPS.

preview
capx
B
78
S
21
G
23
Posts: 513
Reputation: 18,623

Post » Sun Aug 18, 2013 10:47 pm

@Cipriux - sorry for my ignorance, but I'm still a bit confused. The thing is, I enable the character to be able to dash through walls. To do this, I have an indicator sprite that basically states "if indicator is not overlapping wall or black space, disable collision and move towards X,Y at 1500*dt". So whats happening is I'm dashing into empty space, but because the distance isn't the same, it overshoots OVER a wall and into a solid.

I see what you're saying about the instance variable, but I'm also trying to create a "push" at the end of the dash using a platform vector.

Also, not to open up another issue, but you say that Bullet behavior uses dt for speed, but my bullets when at a low fps go right through solid objects and will only occasionally hit them.

The way I understand dt is that you use it to make sure the same value of whatever action (rotating, moving, etc.) is always used based on actual time instead of ticks. Is this not the case?

Again, sorry for the ignorance - I'm a complete noob when it comes to programming, and I'm trying to wrap my head around it.ome6a17172013-08-18 22:48:36
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Sun Aug 18, 2013 11:39 pm

@ome6a1717 I am not an expert, no need to apologize.
Hm...I do not understand the way your game is played...but in principle is similar to a pool/billiard game? I mean: the object is moving with a big speed, it has a direction vector.
I do not know how to overcome this issue. Maybe have some variables to save the last position and compare to the current one, so you can calculate the direction vector...

B
78
S
21
G
23
Posts: 513
Reputation: 18,623

Post » Sun Aug 18, 2013 11:46 pm

Maybe build an invisible sprite representing the vector and use that for collision check (like a linear tail)
B
78
S
21
G
23
Posts: 513
Reputation: 18,623

Post » Mon Aug 19, 2013 12:20 am

[QUOTE=Cipriux] Maybe build an invisible sprite representing the vector and use that for collision check (like a linear tail)
[/QUOTE]

@Cipriux - this is exactly what I'm doing, and it works brilliantly as long as the frame rate doesn't mess up my instance variables subtracting every 0.1 seconds.

I think my main issue is more than just figuring that out or why the bullets don't collide at low fps - it's really learning the proper way to program in C2.

Say I wanted to do this:

Every 2 seconds, have an enemy choose whether or not he should attack or not (using the choose expression). How would you set the "every 2 seconds" so it's the same at every frame rate & every pc?
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Mon Aug 19, 2013 6:40 am

@ome6a1717 Every x seconds is frame independent post. The problem appear when the framerate is below 10FPS....Construct 2 forces everything to behave like is moving at 10 FPS. So for example if you machine is soooo slow that the game runs at 5 fps...the timescale will slow down so that sprites will not appear to teleport around the screen. For this scenario 1 sec will be sloweed down to 2 seconds.

Ashley says: "If the game runs *below* 10 FPS, it will start slowing down. At or above 10 FPS it should still run every 1 second if the event says every 1 second. If that's not happening for some reason, share an example."
So every x seconds will trigger every x+/-dt (I think). It will not happen every 1000 milliseconds exactly...if you want to check for the exact number of ms you can use system.wallclocktime to verify and maybe update your events.

p.s. Even in Microsoft Visual C# if you put a timer, the smallest precision will be more than 14 ms


capx exampleCipriux2013-08-19 06:55:33
B
78
S
21
G
23
Posts: 513
Reputation: 18,623

Next

Return to Construct 2 General

Who is online

Users browsing this forum: kanjmarrie and 5 guests