get position x pixels away from object at angle y

0 favourites
  • 13 posts
From the Asset Store
Vintage steam pixels for your UI! 125 unique assets in a single pack!
  • so essentially, I want to get the x and y position of somewhere that is 2048 pixels away from my player character, but is also at the angle between the player and the mouse cursor. is this possible?

  • x=yourloc.x+dist*cos(theta) y=yourloc.y+dist*sin(theta)

    dist=2048

    theta=angle(yourloc.x,yourloc.y,mouse.x,mouse.y)

  • x=yourloc.x+dist*cos(theta) y=yourloc.y+dist*sin(theta)

    dist=2048

    theta=angle(yourloc.x,yourloc.y,mouse.x,mouse.y)

    Apologies but that didn't seem to work

  • Mouse.x(layer)

    mouse.y(layer)

    Return the position of the mouse cursor in layer co-ordinates, with scrolling, scaling and rotation taken in to account for the given layer. The layer can be identified either by a string of its name or its zero-based index, e.g. Mouse.X("HUD").

    Did you make sure you got the right mouse coords? Are you parralaxing or zooming or scrolling?

    also note my notation for x, y is not the same as yours, your x is my dist, your y is my theta. I made this notation change because x,y is commonly a coordinate and it is consistent with C3 notation.

  • this is what i currently have. which doesnt seem to work

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How do you know it doesn't work? The expressions look correct to me.

    Instead of raycasting, try spawning a test sprite at those coordinates and check if it appears in the expected location.

  • How do you know it doesn't work? The expressions look correct to me.

    Instead of raycasting, try spawning a test sprite at those coordinates and check if it appears in the expected location.

    huh you're right, no clue why the raycast wont work then :/

  • Hitdistance would return 0 when the ray doesn't hit anything. Check that there are in fact obstacles and that you've configured them correctly in LOS behavior.

    Or maybe the ray hits the player object itself, or some other object attached to the player.

    It's difficult to speculate without the project file.

  • Hitdistance would return 0 when the ray doesn't hit anything. Check that there are in fact obstacles and that you've configured them correctly in LOS behavior.

    Or maybe the ray hits the player object itself, or some other object attached to the player.

    It's difficult to speculate without the project file.

    apologies for the delayed response but ive done a bit of tweaking, and ive got it to "half work" of a sort. it is shooting the ray out past 0 pixels now, but it seems to sometimes randomly not go far enough, like, it will shoot out but it will fall short of the solid object, the distance it falls short of seems random, at some points it works perfectly and goes to the wall, at other times it practially goes nowhere, like 5 pixels out from the player when the wall is sat 500 pixels out. completely random. ill send the project file here:

    https://download1322.mediafire.com/67biei4kdr5gWOXfPnmzV3TJAQgSnjQiPaO54nrN4jT6H4F8ANUZE4gg0NLoDG2lWVlK42VW1Ogce2iKCcFmvpABWGKrVEIyInuLIjF1h1hBr6E3UCcDqZBVDHP30OwM-Edbrxr43FbGgXobfeQXzhAQ9KF561p5hEQ1c6QmZ3g9_jc/lwcth4qd9w2qzj2/2d+Platformer+Shooter+Game.c3p

    When ingame, you can use left click to shoot the laser, but you will find the length of the laser is seemingly random.

  • You have a mistake in "Cast ray" action.

    In "to Y" field you have Player.X+2048*sin(angle(Player.X,Player.Y,mouse.X,mouse.Y))

    It needs to be Player.Y

  • You have a mistake in "Cast ray" action.

    In "to Y" field you have Player.X+2048*sin(angle(Player.X,Player.Y,mouse.X,mouse.Y))

    It needs to be Player.Y

    that would be my problem, sorry for being so dumb

  • No worries, I've made this same mistake countless times! :)

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