Help with a movement behavior plz

0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I've implemented your method and it's working very well, thanks a lot!

    but I have a question, I'm trying to detect if the sprite is moving to the right, it will face to the right, if moving to left, face left, etc.

    Is there a way?

    before that I was comparing his angle to detect which direction he was facing but now he's always at the same angle so I have no idea how to do that.. I trying the within angle but not sure if it's the right choice..

  • You don't want the sprite to rotate, only face the direction, but how many? 2 - left/right or 4 - left/right/up/down? What if the destination point is diagonally from the sprite? I'll try to make an example.

  • 4 directions

    maybe compare his distance of x and y to object??

  • New example

    Here's how it works, this picture could also help you.

    <img src="http://dl.dropbox.com/u/10457408/Construct/ENG_FORUM/C2HowDoI/MovementBehavior/pic.png" border="0">

    The sprite has 4 animation frames for 4 possible directions. A frame is chosen on where you click the mouse and the position of the sprite. It's divided into 4 sectors.

    frame #0 has sector 315? up to 360? and from 0? to 45?

    #1 = 45? - 135?

    #2 = 135? - 225?

    #3 = 225? - 315?

    On the bottom part of the picture - the angle between the click of the mouse and the sprite is about 110?, so the code selects frame 1 (arrow is pointing up).

  • Dude that method u used to calculate his direction is extremely complex hehehe but it works! Somethings u used in the event i have no idea what they are.. like 'floor' and this ">= 315 ? 0 :" part.. but once again thanks!

  • Noga your formula is overcomplicated

    First using the same angle order as c2 (0 is to the right and then you move clockwise) makes the formula way easier.

    You can sum it up as round(animationFramCount*angle/360) but as you well representated in your image you need to offset the angle a bit so the direction the sprite shows represents the center of the range of angle and not the minimum.

    So it should look like

    ceil(animationFrameCount*angle/360-0.5)

    Then to avoid negative result (for angle from 0 to 180/animationFramCount),

    you just have to offset values and modulo them

    ceil(animationFrameCount*(1+angle/360)-0.5)%animationFrameCount
  • Yann

    I've never been good at math, everything I do is trial/error<img src="smileys/smiley9.gif" border="0" align="middle" />. Yeah, I didn't know how to offset the angle, so I used conditions. I'll look into your example.

    edit> That's exactly what I wanted, just didn't know how. Never though I'd regret I haven't been more attentive at math classes at school, what a paradox<img src="smileys/smiley1.gif" border="0" align="middle" />. Thanks Yann.

  • Its possible instead of animations frame, use new animations?? this way i can animate each of them.. im at work now so I didnt ever tried this yet

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, use action "Set animation" and name them "0","1","2" and "3". Haven't tried it, but this should work.

    Ok, can't use a number as the name, you'll have to use "&" operator.

  • I've implemented the Yann's method and it worked very well, I also used different animations instead of anim.frames so It looked like:

    "animation"&str(ceil(4*(1+angle(waypoint.X,waypoint.Y,units.X,units.Y)/360)-0.5)%4)

    many thanks to Noga too for those useful tips and solutions ;)

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