GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Stopping MoveTo Touch with collision

My first go at a game in GS.

I have an actor that I want to move to the touch location.
But I want it to stop if the collision object is in the way.
And then move again when a new touch is registered.

I've been running around in circles with this one all day. And I just feel like this is something that should be real easy in GS.

Any help or a point in the right direction would be great.

I can get the actor to stop on collision, but I can't get it to move again after that.

Thanks in advance,
C





Comments

  • tatiangtatiang Posts: 11,815Member, Sous Chef, PRO, Senior Sous-Chef
    Post a screenshot of your rules. It may be that you are preventing movement because of a collision that is occurring when your actor is stopped.

    If you upload an image to a file-sharing service, you can post the URL here as follows (remove the $ symbol):

    <$img src="URL">

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • vonshavingcreamvonshavingcream Posts: 5Member
    I took a shot of what I currently have. I know what is here is wrong. I've been trying to fiddle with it all day to make some progress. Although I have not been very successful.

    http://i.imgur.com/eVe38sY.jpg

    Basically This is what I have worked out so far in terms of logic.

    Timer = 0;
    if Actor.HitWall(boolean) = false
    then
    Move To Touch Location

    I also have this
    Timer = 0;
    if Actor Collides with Wall
    then
    set Actor.HitWall(boolean) = true;

    I can get the Actor started moving and it works until it hits the wall, then it is just chaos.

    I have
    Actor.physics.bounciness = 0
    Actor.physics.movable = 1

    Wall.physics.bounciness = 0
    Wall.physics.movable = 0

    I can't think of anything else that might be worth mentioning.

    thanks for any help.

    C
  • ElfizmElfizm Posts: 489Member
    So from what I gather you want to touch a position and let actor move there but if it hits a block stop.

    So I would do what you have in your rules but in the otherwise section of the if hit block is false rule, add a move behavior and change it to 0 speed.

    Maybe try that if that's what your talking about. Because I think the way you have it is that it is going to keep moving or trying to move even if it has hit a block unless you put in that otherwise statement.
  • vonshavingcreamvonshavingcream Posts: 5Member
    Elfizm .. yes that is exactly what I want to do.

    okay .. setting move to 0 makes sense. I just assumed that when the actor stopped, it stopped. But it appears that is still trying to get to the MoveTo location even though the wall is in the way.

    Is there a physics setting that would force the actors speed to goto 0 when it collides with the object?
  • ElfizmElfizm Posts: 489Member
    Pretty sure putting a rule like mentioned before in the "otherwise" section of the rule might help. If that doesn't work let me know.
  • vonshavingcreamvonshavingcream Posts: 5Member
    edited January 2013
    that didn't work. from what I can gather from the debug console it is mainly because the actor is still touching the wall, so the if(hitwall is false) statement never resolves.

    i can code this answer with minimal lines of javascript. I don't understand why this is so difficult to make happen in GS. I really want to like this software, but I am getting frustrated by the minute.

    a very simplified code for what I am trying to do

    var cannonBall wall touch
    if(touch)
    while(move cannonBall to touch)
    if(cannonBall hits wall)
    stop cannonBall

    I know that the code is very basic, but I don't understand how something this simple can be so complicated in GS. I really feel like I am missing something.

    Here is what I did.
    I put a log debug message in to check if attribule.Hitwall is true or false.

    when I start the game the debug displays
    Log(Actor: GameBoard_CanonBall): I am NOT touching a wall

    over and over again.

    when i touch the screen, the ball moves to the correct place.

    when I touch an area that would force the ball to hit a wall i start getting this.

    Log(Actor: GameBoard_CanonBall): I am NOT touching a wall
    Log(Actor: GameBoard_CanonBall): I am touching a wall
    Log(Actor: GameBoard_CanonBall): I am NOT touching a wall

    over and over again.

    How do I pull the ball off of the wall once it collides with it?





  • ElfizmElfizm Posts: 489Member
    edited January 2013
    Ok got it.... I think.

    Have two actors, actor one is moving. Actor two is the wall.

    Change bounciness to 0 on both actors.

    Actor one:
    Constrain self.rotation to zero

    Collide with actor 2 ( the behaviour not the rule

    Rule,
    When touch is outside
    Move to game.touch1 x and game.touch1 y

    (make sure you tick run to completion)


    A new rule that says
    When collide or overlaps with actor 2
    For 0.1 second ( run to completion)
    Move at zero speed.


    Then go on to actor two and make it unmoveable.

    Hope that works for you

  • vonshavingcreamvonshavingcream Posts: 5Member
    edited January 2013
    Ok.. that got me the closest I have been in two days. However, the problem still arises in this line
    Elfizm said:


    A new rule that says
    When collide or overlaps with actor 2
    For 0.1 second ( run to completion)
    Move at zero speed.

    Once actor1 hits the wall no matter where you click after that, the actor1 won't move anymore.

  • ElfizmElfizm Posts: 489Member
    Did you type it correctly because I made a test and it works fine.
    I can just email it to you if you want to pm your email address

    Otherwise

    I don't know what's wrong.

    The rules are separate, they are not put in to one rule maybe you did that.


    So for actor one you should have four different code groups.

    When I test it and run into the wall. I cab either move up or down or back ect but no through it.
  • Just wanted to say thanks. I finally got this working with your help. I was working on some other aspects of the game and finally came back to this.

    Thanks for helping me.
  • stueynetstueynet TorontoPosts: 166Member

    @vonshavingcream said:
    Just wanted to say thanks. I finally got this working with your help. I was working on some other aspects of the game and finally came back to this.

    Thanks for helping me.

    @vonshavingcream‌ I know this is an old thread but if you figured it out it would help if you posted it the solution. I am actually having a similar issue where I need to use "Move To" with Run to completion on so that it completes the move each time. But if you move into a wall, it never is able to complete the move and it basically just tries forever to move to the spot that is behind the wall.

    My Latest GS Game - Tiny Spirit
    My First GS Game - Dashing Ralph

Sign In or Register to comment.