Move towards the mouse

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I'm experimenting with moving my player-ship with the mouse, but I don't want it to move directly to the mouse location (that's way too fast). The best solution so far is similar to the example where the ship moves using bullet behaviour. This works really well and feels good but there's one problem - I don't seem to be able to limit the position of the ship. I need to limit it to just the lower half of the screen. Is there some way I can do that using bullet behaviour?

    The 2nd option I can think of is how I'd do it in code - using math to work out the angle between the current position and the mouse position then move so far along that angle. I can't remember the math for this but I can probably find it, or does someone already know how it's done?

  • this is one way to do it

  • You could use the 'lerp' expression like in podpathos' example, it's a nice way of doing it. If you want the angle math you mentioned though, this should cover it:

    MoveAtAngle.capx (r106)

    To get the angle you can simply use C2's 'angle' expression, I've also used 3 variables to make it easier to see what's going on, but you could do it without them.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks guys. For some reason I couldn't access the forum for the past 24 hours but in the meantime I seem to have solved it. I just used the bullet movement as I was doing and don't allow it to change the angle of the ship since it's a scrolling shooter, and can limit the ship to the boundaries - I was trying to use WindowWidth/Height but didn't realise that scales, but it works fine when I switched it to LayoutWidth/Height.

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