How would I Set the Offset of Sprites Origin?

0 favourites
  • 5 posts
From the Asset Store
A set of sci-fi / cyberpunk themed platformer characters
  • Hey guys!

    I'm evidently new here, and I look forward to growing within this community! So far I love what this program has got to offer to indie developers of all programming experiences. My programming skills tbh [3/10] 10 best.

    Anyways, I'm trying to get my players Torso to pivot from hips on Legs obj., which I can do successfully. Where things go wrong is when the angle of Torsos to Mouse.X/Y. Since ImagePoint 1 is set to barrel of gun, and image angle is based off Torso Origin to mouse.X/Y instead of gun barrel to mouse.X/Y , there's always that odd angle of trajectory from bullet to mouse coordinates which causes bullet to go over or under mouse.

    What method(s) can I go about to have gun barrel precisely lock onto my mouse coordinates? That way, when I move the mouse, barrel is always aligned/leveled with mouse (along with torso, as it's a part of the same object), AND have bullet fire from barrel right into my mouse as any shooter would like.

    *I still want Torso to pivot from hips!*

    Mucho Thanks!

  • Would this work for you? I've split the arm into a separate sprite to the torso, which allows more accurate aiming - you can restrict the arm movement range to that of the torso if you want them to look fixed together. ... .capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sir 'mekonbekon', that was marvelous! Thank you

    Just so I could gradually become less dependent on others help, I'm trying to understand what you did there but it's honestly confusing.

    Like the order of x1,y1, x2,y2 (the mouse. and self. order), and the two degrees. How would one know if it's necessary or which degree slot does what? Experimenting? Sheesh!

    Okay, now if I required more precision on barrel-to-mouse...wouldn't I need to create an offset? ORRR, I could align by drawing, shoulder/barrel exit at same height starting at 0 deg. so it's as if it's taking coordinates from barrel. The con about that is inaccuracy at long distances which my game will have.

    An idea... would it be a good one if we could have have projectiles travel at a slightly altered angles after mouse is > than specified distance and Y pos/height? and vice versa with < (because fyi, projectiles at longer distances that are not 100% aligned will have gap on south of mouse or north of it depending on Y pos/height. More noticeable with greater distances.)

  • Yeah I had to do quite a bit of experimenting myself to work out the correct order and angles - try fiddling around with the two angles to see how it affects the limits of the torso position.

    As you suggest, you could also adjust the angle of the bullet at the point of creation based upon the mouse position - you're going to be pointing in approximately the right direction anyhow, so if you set the bullet's angle using a similar scheme to this to ensure it's range of angles was limited you could get pinpoint accuracy. If I get a chance tomorrow I'll see if I can knock something up, and add some comments to the original demo to explain the code.

    P.S. - I got a bit carried away with this demo and came up with this: <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Dude, I'm very grateful for your help, especially on this project that means alot to me.

    :O Lol the game is kinda fun. It's a nice one for being made spontaneously. Okay I look forward to it although it's really not necessary.

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