NPC Animation to correspond with Movement Angle

0 favourites
  • 7 posts
From the Asset Store
Fantasy RPG Human-NPC assets pack of 15 characters
  • Hello All,

    I've been searching through many other threads and finding variations to this NPC angle issue, but can't seem to find the solution, though I'm sure it must be a simple one.

    I am very new to Construct, and right now I'm experimenting with a top-down 8-directional NPC movement.

    I am just wanting to base the angle off of the NPC's own directional movement, (not compared with the player or another entity's position)

    Basically all I want to do is:

    • If NPC angle is within 45 degrees of north (260?) then play "north" animation.
    • If NPC angle is within 45 degrees of south (90?) then play "south" animation.

    In my event sheet I'm using: NPC 'within 45 degrees of angle x' then 'Set Animation x' for both of those conditions.

    However when I play it, the NPC will not deviate from its original animation no matter what angle it is moving at.

    (Btw, For NPC movement, I'm using a Set Position Lerp to have the NPC automatically follow the player's position. )

    Any suggestions? :)

  • Are you using 8-directional behavior for the NPC movement?

    If so,

    Did you check that 'set angle' is set in the 8-directional properties?

    If you are moving it via events (e.g. lerp), you just need to do this:

    every tick:

    instance variable angleOfMovement = angle(previousX, previousY, self.X, self.Y),

    previousX = self.X

    previousY = self.Y

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the response, Sqiddster

    I was originally just moving the NPC by the Lerp event.

    PreviousX is not an accepted angle parameter. Did you mean Self.PreviousX with PreviousX being an isntance variable?

    Now I made a new version implementing 8-directional NPC movement. This seems to be working:

    Every Tick:

    Move NPC 1 pixel at Angle of angleOfMotion

    Every 3 Seconds:

    Set angleOfMotion random(360) + monster1.8Direction.MovingAngle

    I am then using Between Values of angleOfMotion to play the correctly oriented animation.

    Now a new problem I have is that as soon as one instance of the NPC moves at a certain angle to change animations, all the other instances change animations as well. I assume this is a Unique ID problem, but I was unable to find an answer in the FAQ.

    Is there a simple way to have any Animation changes, other changes, etc. apply only to the UID which met the conditions?

  • Add a "For each" loop to your event. This will loop through all the instances of the object you choose and make sure the changes are applied only to the ones that meet the conditions.

  • Ah, that is simple. Thanks Nimtrix.

  • If you are moving it via events (e.g. lerp), you just need to do this:

    every tick:

    instance variable angleOfMovement = angle(previousX, previousY, self.X, self.Y),

    previousX = self.X

    previousY = self.Y

    Okay, I've done this to get the angle.. now I'm just having trouble setting the condition based on angleOfMovement. It appeared to be working for finding angles between 0-45, 45-90, 225-315, and so forth. But when it crossed over zero, like between an angle of 315-45, it seems to break.. I assume because it's reading the angles as values.

    The logic I keep going to is to use:

    System - In Between Values

    315 < npc.angleOfMovement < 45

    Also, I tried replacing the values with angles so:

    Angle(0,0,1,-1) < npc.angleOfMovement < Angle (0,0,1,1)

    There is also the "between angles" and "within angle" on the NPC, but these appear to be locked to the original npc angle parameter and not my angleOfMovement instance variable??

    Hopefully the above problem makes sense.. I just want to perform an action based on whether the moving angle of the sprite is within 45 degrees of 0, 45,90, 180 degrees, etc.

  • A cap would be really useful for understanding your problem

    I'm not sure .. but it seems like it may be caused when values are going above 360 or below 0

    I'd recommend adding some sort of debug text object in the layout, and get that to display all the values that are involved.

    if any are above 360, then include a '%360' to the value.. this will cause it to loop back around to 0 if it's above 360. eg: 370%360 would equal 10

    If it's below 0, then add 360 to it.

    However I did this before they added the "is between angles" and "is within angle" conditions, and also the "anglediff", "anglelerp" expressions.. I have a feeling these would have solved my problems easier.

    But yeah, post a cap. :p

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