Making an object stop/custom movement

This forum is currently in read-only mode.
From the Asset Store
Make your own platformer for both the web and mobile easy with this Santas Platformer Template, FULLY DOCUMENTED
  • 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 , 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 .

    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 .

    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

    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.
  • 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'))

  • Thanks, I get how that works now. It makes sense too.

  • 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.

  • 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.

  • what do you mean by an additional condition?

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here are two ways to check if two sprites have the same x and y positions:

    + 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]
  • Thanks. I'll try out these methods and see if they work.

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