Move towards the mouse

Get help using Construct 2

Post » Wed Oct 10, 2012 6:00 pm

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?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Thu Oct 11, 2012 3:50 am

this is one way to do it
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Thu Oct 11, 2012 1:54 pm

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.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Oct 11, 2012 3:39 pm

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.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot], YoHoho and 12 guests