0 Favourites

Enemy movement question

This forum is currently in read-only mode.
  • 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.
  • 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.

  • 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.

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

    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.

  • 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.

  • 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)

  • 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!

  • Nah, wasn't you. I forgot about the need to timedelta the first part in my earlier post. Sorry about that.

  • damn, arima, you're right. So, this is a perfect example of "four eyes see more than two"

  • Wow, this is good stuff to know.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)