How do I set angles with Line of Sight?

0 favourites
  • 9 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • There is something weird going on. As soon as I preview the Layout, some events do not trigger even though I know the conditions are being matched. Then, some time later and after jumping a few times, it starts working normally.

    I'm using "Object Has Line of Sight of another Object", but...for some reason it doesn't work.

    Here is link of the file:

    drive.google.com/file/d/1h5dOkxy9Zl3sSgn95PnwoeiZ1vB14uhC/view

    Here is where I'm struggling with:

    prntscr.com/r8lamr

  • What are you trying to do?

    Works fine as written.

  • What are you trying to do?

    Works fine as written.

    Thanks for your reply, oosyrag.

    I want to, when jumping towards the next platform, detect the landing zone orientation - If it's a vertical or an horizontal edge. Then, when landing on the next edge, I want obj_PlayerPointer to have the same angle it had in relation to the previous edge jumped from, and so on. Always replicating the same angle from the previous jump.

    See this image, please:

    drive.google.com/file/d/1yfQMKTkokXxfaw_reBbGD6cW8oyYmPP-/view

    I used 45 degrees as an example, but I want it to work with any angle and with any edge orientation.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You won't be needing the "Object Has Line of Sight of another Object" condition.

    In your drawing, it looks like when you jump to another surface, the angle will be set to go back the way you came from, so if you jump you'll go back to where you started. This is simply a 180 degree turn from the previous heading upon landing, or collision with target platform. However, that is independent of target platform rotation or angle, so the target platform orientation doesn't matter.

    In the event that you wanted the new angle to be a reflection off of the target platform surface (like a ball ricocheting off a wall on a pool table), which is what I understand from your written description, you'll want to do the following:

    Upon jumping, use the cast ray action from the player object towards the direction you are jumping.

    In the following event, use the Ray Intersected condition to check if it hits a destination surface. Then you can get the reflection angle with the ReflectionAngle expression, plug that into the action where you set the new angle, upon colliding the wall or right after you jump or whenever you want.

  • In the event that you wanted the new angle to be a reflection off of the target platform surface (like a ball ricocheting off a wall on a pool table), which is what I understand from your written description, you'll want to do the following:

    Man, I confess I mess up hard when trying to explain this xD

    I don't think it has something to do with reflection. Dop2000 already mentioned Reflection on another topic I made, but I don't think it does the trick in this case, since I'll have many different objects to land on in many different orientations. Reflection would retrieve a different angle based on how the ray collides. What I want to achieve is the same angle everytime I jump.

    My fourth try trying to explain this, here I go xD

    What I want to achieve is:

    Let's say I'm on a wall right side (right edge). I want to jump off this wall towards another area and obj_PlayerPointer angle is, at this moment, 45 degrees, pointing Southeast - as Construct angle 0 is East. The platform I'm pointing to and going to land afterwards is a floor - going to land on it's top edge.

    Then, as soon as I press Space Bar and jump, I want that obj_PlayerPointer get it's angle set to a new value, and this value being a value that results on the same angle difference obj_PlayerPointer had in relation to the previous edge I was at, the edge I jumped from.

    And I want it to always do it, every time the player jumps!

    Here is another drawing: prntscr.com/r97wxx

    The angle doesn't need to be 45. I just want obj_PlayerPointer to maintain the angle - the one used on the previous jump - for the next jump, no matter what angle was used.

  • In that case you simply take the difference in angle between the origin object and the target object, (assuming they all used the same origin angle and are rotated after), and add that to your pointer object's angle.

    You'll need some way to pick the origin and target surface to be able to get the angle expressions from them. First thing that comes to mind is to use a invisible helper sprite on overlap to get the right surfaces to get numbers from, but there are probably a few other ways to go about this as well.

  • In that case you simply take the difference in angle between the origin object and the target object, (assuming they all used the same origin angle and are rotated after), and add that to your pointer object's angle.

    You'll need some way to pick the origin and target surface to be able to get the angle expressions from them. First thing that comes to mind is to use a invisible helper sprite on overlap to get the right surfaces to get numbers from, but there are probably a few other ways to go about this as well.

    Thank you again, Oosy. To be honest, I kinda get what you mean, but just "kinda" hahaha. Not your fault though!

    If possible, I would really appreciate if you could simulate/exemplify how it would work with numbers. Anyway, I'll take a look at some expressions and see how I could achieve this. I confess I'm pretty lame at Math at the moment.

    Regarding targeting, I thought "Has Line of Sight of X" would to the trick when it comes to getting target surface and "Is overlapping at offset" would cover origin surface, but...I don't know, I'm messing up somewhere! Gonna mess around a little bit more tonight.

    Plus, when you say "origin object" and "target object" in the first sentence, what objects are you referring to?

  • The angle of the surface you are jumping from would be the origin, and the angle of the surface you are jumping to would be the target.

    I can put together an example when I get a chance.

  • Sorry took a bit.

    See if this is what you're looking for.

    dropbox.com/s/uuh8u9a2yn6ndgo/preserveangle.c3p

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