How do I Set an object's Angle to it's Sine Angle?

0 favourites
  • 11 posts
From the Asset Store
It's here!
$4.95 USD
Creepy and nasty horror track. It's terrifying from the beginning till the end. Goosebumps guaranteed
  • I want to have an enemy face in the direction it is moving towards relative to it's Sine.

    Anyone have any clue on how you could code this?

  • If you have access to the X and Y motion vectors for your object, the angle of motion can be obtained from the expression angle(0, 0, VectorX, VectorY). However, I may be misunderstanding exactly what you're looking for -- a capx or a diagram would be useful.

  • If you have access to the X and Y motion vectors for your object, the angle of motion can be obtained from the expression angle(0, 0, VectorX, VectorY). However, I may be misunderstanding exactly what you're looking for -- a capx or a diagram would be useful.

    Yeah, let me draw you a quick picture.

  • Not sure if that worked, but basically I'm trying to have the enemy face in the certain direction in which he is moving. So when the sine is moving left - Angle Left. When the sine is moving Right - Angle Right. ect.

  • So yeah... good old Scirra doesn't want me to give you a picture... Annoying how they don't have a direct profile upload box and have you post it elsewhere and link it in, just to tell you you haven't posted enough and can't link anything...

  • imagehousing.com/imageupload.php?id=1226259

    just add w_w_w. in front.

  • I've prepared a quick example to show how this can be done. I'm not sure how you have your object moving, so I set this one up to move at 100 pixels per second along the X-axis and to use the sine behavior on the Y-axis, but the same concepts should apply regardless.

    Sine Facing example

    There's a small bit of calculus involved to get what we want. We start off with our position functions for the object, which are as follows(not Construct 2 expressions, but close):

    X: InitialX + 100t

    Y: InitialY + Magnitude * sin(CycleAngle)

    Take the first derivative to find the velocity:

    Vx: 100

    Vy: Magnitude * cos(CycleAngle)

    Now that we have the velocity, we can use the angle() expression that I outlined in my original post to find the direction of travel. Note that with the sine behavior, Sine.CyclePosition is just the normalized angle used when calculating the oscillation, so we multiply 360 to turn it back into degrees.

    As an additional note, please try to avoid so many posts in a row in the future -- you can always edit new information into your previous post.

  • Alright, will do. Thanks, this is pretty much what I'm wanting to accomplish with my sprite, the biggest difference is that is it angled downward and is moving using a bullet which changes as it passes over an invisible line. With this code I could just change it's Self.Y to whatever speed that I'm wanting so that's not really an issue.

    Quick question though: If I were trying to code this to go at a downward angle and with a bullet behavior to the object, would this solution still work the same? The way you explained this is a bit complicated and I'm not sure if I follow what you are saying when it comes to replicating this mechanic.

    When setting the object's angle this line of code: angle(0, 0, 100, Self.Sine.Magnitude * cos(Self.Sine.CyclePosition * 360)) -- I'm not sure I follow this entirely.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • here a very generic expression that adapts that principle and should work regardless of how movement is applied (you probably need to set oldx and oldy to the current position after creating the object, so you get no jitter on the first frame). Ofc if the bullet behavior sets the angle, those two might collide, so in case it is needed, deactivate that.

    https://copy.com/eCpuz2P8WGfKCpyS

    If it jitters too much on irregular movement (like slow mouse drag) or maybe because of bad framerates, you might have to take the difference over more than 1 frame, then the code gets a bit more complicated.

  • I don't really get these solutions. Unless I'm missing something I think you could just set the object's angle like this: 90+Object.Sine.Value

    If you're letting the bullet behavior set the object's angle, you might want to set the sine to "value only" so they don't fight each other.

    example https://dl.dropboxusercontent.com/u/135 ... hingy.capx

  • Hope this helps me. thx///

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