Speed and movement question

MattButlerStudiosMattButlerStudios Member Posts: 486
edited September 2014 in Working with GS (Mac)

I have 2 questions that need to be addressed.

1) How do I make an object (a ball for instance) not always move in the same direction when hitting an object. For instance say I have a room and the ball keeps hitting the floor and then hitting the ceiling endlessly. I want the ball to sometimes change it's angle and hit the wall occasionally. How do I make this happen?


2) How do I make the ball (as described above) maintain a constant speed and never change from that speed?


Thank your for your help in advance. -MattButlerStudios

Comments

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    Anyone?

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited September 2014

    @MattButlerStudios‌, to point 1

    Put the following rules in the actor:

    **Rule**: When All (this checks left and right)
    
    "Num Expression" vectorToAngle(self.Motion.LinearVelocity.X, self.Motion.LinearVelocity.Y) = 0 
    
    and
    
    Actor collides with Wall
    
    then
    
    Change Velocity
    
    Direction = vectorToAngle(self.Motion.LinearVelocity.X, self.Motion.LinearVelocity.Y) + random(-10,10) relative to scene
    
    Speed = lets say 300
    
    
    **Rule**: When All (this checks up and down)
    
    "Num Expression" vectorToAngle(self.Motion.LinearVelocity.X, self.Motion.LinearVelocity.Y) = 90 
    
    and
    
    Actor collides with Wall
    
    then
    
    Change Velocity
    
    Direction = vectorToAngle(self.Motion.LinearVelocity.X, self.Motion.LinearVelocity.Y) + random(-10,10) relative to scene
    
    Speed = lets say 300
    
  • HopscotchHopscotch Member, PRO Posts: 2,782

    @MattButlerStudios‌ ,

    for point 2, make sure that friction is set to 0 in all walls and actors that collide.

    Also make sure drag is set to 0 in the moving actors.

    This way the motion should not slow down over time, despite collisions.

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @Hopscotch‌ Wow, thank you for the excellent response!

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited September 2014

    My pleasure @MattButlerStudios‌

    Just to add to your constant speed question, bounciness should be set to 1 in all colliding actors.

    So, a system with

    • bouncyness = 1
    • friction = 0
    • drag = 0

    will conserve all kinetic energy.

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @Hopscotch‌ just wanted to thank you again for the help. Everything turned out great!

Sign In or Register to comment.