Making an object stop/custom movement

For questions about using Classic.

Post » Thu Jul 15, 2010 5:18 am

I'm just trying to see if my idea should work or if I'm doing something wrong. I have a sprite with the bullet behavior that moves towards where the mouse was clicked. I'm trying to get the sprite to stop when it reaches where the mouse clicked. Sadly :cry: , it won't stop. Here's what I have. I am using version 0.99.62.

condition:
right mouse button clicked

actions:
sprite: set speed to 250
sprite: rotate 360 degrees towards (MouseX, MouseY)
System: set global variable 'mousex' to MouseX
System: set global variable 'mousey' to MouseY

conditions:
sprite: Y Equal to global('mousey')
sprite: X Equal to global(mousex')

action:
sprite: set speed to 0

Also, if anyone has an idea for how to select certain troops and unselect them once they have been assigned to do something it would be great. Thanks :D .

Edit: I scrapped the variables and instead am using another sprite that goes to where the mouse right clicked. That part works fine now. I'm just wondering if there's anyway to make an object selectable and unselectable.

Edit: I used private variables for determining whether an object was selected (tell me if there's a better way please). Right now, I'm wondering if there's a way to use custom movement to make an object move towards a position without using rotation. Thanks :D .

Edit: I found a way to do it without using custom movement, though I would still appreciate it if someone could explain a way to use it for this purpose. Instead, I used a sprite that had the bullet behavior and set the position of the first sprite to the second so that the first sprite wouldn't rotate. For anyone interested, here's the code that shows how I did it all.

Note:
sprite1 is a stickman, 'selected' is a private variable for stickman, rotating_sprite is a point whose opacity is 0 and has the bullet behavior, stop_sprite is a small box whose opacity is also set to 0, mouseandkeyboard object is used

[code:2ww8lwx0]
on left clicked on sprite1
=> sprite1: set 'selected' to 1

on left mouse button clicked
=> sprite1: set 'selected' to 0

on right mouse button clicked
and
sprite1: Value 'selected' Equal to 1
=>
stop_sprite: set position to (MouseX, MouseY)
rotating_sprite: set angle towards stop_sprite
rotating_sprite: set speed to 250

on collision between rotating_sprite and stop_sprite
=>
rotating_sprite: set speed to 0

always(every tick)
=>
sprite1: set position to rotating_sprite.X, rotating_sprite.Y
[/code:2ww8lwx0]

Sorry for all the edits, I made some mistakes and had to fix them. :D
B
2
G
2
Posts: 48
Reputation: 746

Post » Thu Jul 15, 2010 10:16 am

The reason your bullet didn't work comparing mouse coords is because the sprite never had those exact coords to compare with.
Mouse x, and y can have decimal values, as well as the sprite.
Next time try int(), as in:
int(sprite: Y) Equal to int(global('mousey'))
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Jul 17, 2010 6:05 pm

Thanks, I get how that works now. It makes sense too. :D
B
2
G
2
Posts: 48
Reputation: 746

Post » Sat Jul 17, 2010 10:07 pm

I'm having some trouble with overlap. I'm using construct version 0.99.85. It seems that whenever the object is at the same y position as the object it registers as overlapping even though the x coordinates don't overlap. Is this a bug? Does anyone know if there's another way that's simple (I know a much more messier and complicated way but don't want to do it unless I must.) Thanks. :D
B
2
G
2
Posts: 48
Reputation: 746

Post » Sat Jul 17, 2010 11:00 pm

Overlapping will check each pixel unless its set to point on collisions.
Also to do both x, and y you will probably need to do an additional condition.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Jul 17, 2010 11:14 pm

what do you mean by an additional condition?
B
2
G
2
Posts: 48
Reputation: 746

Post » Sun Jul 18, 2010 12:29 pm

The only time it would do that, that I can think of, is if your using overlap at offset.
That requires additional conditions to get all four sides.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Jul 18, 2010 7:43 pm

Here are two ways to check if two sprites have the same x and y positions:
[code:1y35dq1p]+ System: Always (every tick)
-> Sprite: Set collision mode to Point
-> Sprite2: Set collision mode to Point

+ Sprite: Sprite overlaps Sprite2
-> Do Actions

+ System: Always (every tick)
-> Sprite: Set collision mode to Per Pixel
-> Sprite2: Set collision mode to Per Pixel[/code:1y35dq1p]
[code:1y35dq1p]+ System: For each Sprite2
+ Sprite: X Equal to Sprite2.X
+ Sprite: Y Equal to Sprite2.Y
-> Do Actions[/code:1y35dq1p]

Keep in mind thought that positions in construct are floating point, so objects will almost never be at the exact same location. But if you want to compare x,y location I'd recommend comparing the distance between the two objects and consider it a collision if they are close enough.

Ex:
[code:1y35dq1p]+ System: For each Sprite2
+ Sprite: Pick by distance(Sprite.X, Sprite.Y, Sprite2.X, Sprite2.Y) Lower or equal 10
-> Do Actions[/code:1y35dq1p]
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Mon Jul 19, 2010 1:57 am

Thanks. I'll try out these methods and see if they work.
B
2
G
2
Posts: 48
Reputation: 746


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests