How do I push opject to mouse position

Get help using Construct 2

Post » Mon Aug 21, 2017 11:06 am

i have sprite spawn object i want to know how to make spawned object to move frome sprite to mouse croshere position i.x move from point a and stop on point b ( mouse crosehere )
B
8
S
1
Posts: 13
Reputation: 426

Post » Tue Aug 22, 2017 4:04 am

Hi ismailsawan... there are many ways you can do it, but there is the "easiest"

If you want it to walk into the crosshair (cursor) you can use a Bullet Behavior, and constantly change its angle of motion to "angle(Sprite.x,Sprite.Y,Mouse.X,Mouse.Y)".
Howdy, I'm HenryPK! I love helping people and making games... Hope we can be friends. (Actually developing Blue in Bitwin Entertainment: https://gamejolt.com/games/blue/321184)
B
11
S
3
G
1
Posts: 68
Reputation: 1,374

Post » Tue Aug 22, 2017 8:57 am

Thank You HenryPK,

exactly i do that but i want the spawned object to stop on mouse cross hair i click on screen... the bullet behavior make spawned object move out the layout can you find way to do that

great thanks for your help.
B
8
S
1
Posts: 13
Reputation: 426

Post » Tue Aug 22, 2017 9:34 am

To move to cross hair on screen such as an RTS it is better to use the pathfinding behaviour, the object in question probably having 8-direction behaviour as well. When you click, mouse.x,mouse.y becomes the destination for the object to move to. On click, object find path to mouse.x, mouse.y.
B
53
S
21
G
94
Posts: 2,425
Reputation: 55,563

Post » Tue Aug 22, 2017 1:33 pm

ismailsawan wrote:Thank You HenryPK,

exactly I do that but I want the spawned object to stop on mouse cross hair I click on screen... the bullet behaviour make spawned object move out the layout can you find a way to do that

great thanks for your help.


Oh, you can make it like this with 3 objects (The Mouse, the Sprite, and a "target" invisible(or not) object):

HenryPK wrote:On "Mouse" Click >>
- Set "Target" position to (Mouse.X, Mouse.Y)

When you click, it will bring the target to the mouse position.

HenryPK wrote:"Target" Is On Screen >>
- "Sprite" set Bullet angle of motion to:" angle (Sprite.x,Sprite.y,Target.x,Target.y)

If there's a target on screen, will move towards it

HenryPK wrote:Else (Target Is not on screen) >>
- "Sprite" set Speed to 0

Won't move if there is no target onscreen

HenryPK wrote:"Sprite" on collison with "Target" >>
- "Target" set position to "-Target.Width,-Target.Height)"

This will make the target go off screen when the Sprite reaches its destination.
Howdy, I'm HenryPK! I love helping people and making games... Hope we can be friends. (Actually developing Blue in Bitwin Entertainment: https://gamejolt.com/games/blue/321184)
B
11
S
3
G
1
Posts: 68
Reputation: 1,374


Return to How do I....?

Who is online

Users browsing this forum: oosyrag and 8 guests