Enemy movement question

For questions about using Classic.

Post » Sun Oct 24, 2010 8:31 pm

[code:39ksxogh]
Always- Set Enemy.X to Enemy.value('X')
Set Enemy.Y to Enemy.value('Y')

Enemy.X is lower than Player.x - Subtract 0.03 from Enemy.value('X')
Enemy.X is greater than Player.x - Add 0.03 to Enemy.value('X')

Same goes for Enemy.Y[/code:39ksxogh]

How would I recreate this movement using timedelta? I've applied time delta to it in every way I know how but it just doesn't work right.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sun Oct 24, 2010 9:16 pm

What's the refresh rate of your monitor? Or more accurately, what's your FPS?

Edit: if it's 60, then 0.03*60=1.8, so subtract 1.8*timedelta.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Sun Oct 24, 2010 9:33 pm

What Arima said.

The background: You currently have a fixed value per tick that you substract, but the ticks are of different durations. When using timedelta, you need to know or set a value per second instead of per tick.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 26, 2010 2:12 pm

Thanks, but what I'm trying to do is recreate this movement so it's framerate independant. Using the above code makes the enemy extremely fast using unlimited framerate mode, regardless of how I add timedelta.

It seems I need to scrap the above code and use a different custom movement..one that moves the enemy in a similar but framerate independant fashion..but I'm not sure how :?
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Tue Oct 26, 2010 2:31 pm

[quote="Tokinsom":3j4h8qiz]Thanks, but what I'm trying to do is recreate this movement so it's framerate independant. Using the above code makes the enemy extremely fast using unlimited framerate mode, regardless of how I add timedelta.

It seems I need to scrap the above code and use a different custom movement..one that moves the enemy in a similar but framerate independant fashion..but I'm not sure how :?[/quote:3j4h8qiz]
That's exactly what timedelta is for, so if it doesn't work for you, there's something wrong with the math you're using. If I set the sprite's x to sprite.x + 64 * TimeDelta, it moves exactly 64 pixels per second to the right, no matter the framerate.

I would suggest you create an example cap showing the problem, maybe a few more eyes see an issue that hides from your eyes?

EDIT: Maybe you're not taken into account, how often the condition is met? if the enemy is close to the player for a second, the condition is met your framerate's times. So, when running with 60fps it is met 60x and the enemy's x is affected 60x, with unlimited mode it might be 3000fps and the condition is met 3000x during that second and so affects the enemy's x 3000x. What you would need then is a relative change of the enemy's x not an absolute.

EDIT2: Hmm, thinking about it a second time, this seems to be nonsense, because TimeDelta already makes it relative. There must be something else.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 26, 2010 3:09 pm

Run it once, then switch to unlimited mode and run it again. You'll see how ridiculously fast the objects get.

I mean I know what TimeDelta does, and I've used it successfully for many things. This however..blah. I have no idea what to do with it.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Tue Oct 26, 2010 3:27 pm

Event 1's action's are tick based. You need to timedelta them.

Sprite2.x+(Sprite2.value('x')*timedelta)
Sprite2.y+(Sprite2.value('y')*timedelta)
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Tue Oct 26, 2010 4:00 pm

Ahh that works perfectly. Thanks! Sorry if I was misunderstanding you guys earlier :T Hopefully this will be the last of my time delta questions!
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Tue Oct 26, 2010 4:14 pm

Nah, wasn't you. I forgot about the need to timedelta the first part in my earlier post. Sorry about that.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Tue Oct 26, 2010 4:17 pm

damn, arima, you're right. So, this is a perfect example of "four eyes see more than two" :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests