Actor Movement: special impact

TosanuTosanu Member, PRO Posts: 388

Ok, this one is fun. I am trying to make a hanging object that reacts when it is struck. Basically, i used half the code i once received/worked out on penduluming to create an object 'hanging' from a rope. My goal here is to have the object react to being struck by an object by "bouncing". I want it to react as if the hit has caused it to swing a bit before settling back down. I cant figure out the equation that would work.

My current try is to have an integer Bouncing. If Bouncing is less than 40, being hit by Attacks causes it to go up by 20. Every .8 seconds that bouncing is >0, bouncing goes down by 5. and then i thought maybe a constrain position x, sin function of bouncing sin(self.time(bouncing *10))+start position x. Based on orbits, the idea is that bouncing is the period of the swing and the speed of the swing is also derived from it with the *10.

But right now its incredibly jerky, and because its on self time/sin, it can suddenly pop into any part of the curve. Is there a better way to create this illusion?

Comments

  • TosanuTosanu Member, PRO Posts: 388

    Just to clarify one point. I don't need it to follow a particularly realistic arc since it isnt going to have a wide swing. If i can get this on a purely horizontal back and forth, diminishing movement it would be enough.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    @Tosanu, if you don't want/need the 'swing'. I'd just set it up to use the physics engine. You could use two invisible actors to bounce your object back and forth, adjust the 'bounciness' so is slows naturally.

  • TosanuTosanu Member, PRO Posts: 388

    The problem is i want the "bounce to be a reaction to being struck by a player. This is an Invincible Enemy setup, and the swing is a visual indicator (to go with an audio one) that you did no damage. Im not sure how to use that suggestion to make this visual.....

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited June 2014

    Hmmm, I'm not sure exactly what you're thinking. But here is a little demo I did. Move the player (rectangle) over to hit the little square then move back out of the way... would something like that work?

    Ignore the attached file, wrong one! lol

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • TosanuTosanu Member, PRO Posts: 388

    I appreciate it. I decided to simplify and use an illusion workaround based on interpolating, but I will definitely look over your suggestion for the future. (I have some unfortunate time restraints so i decided to scale back on this after some thought, since on rereading my description here, its not exactly a CRUCIAL feature.)

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2014

    @Tosanu said:
    Just to clarify one point. I don't need it to follow a particularly realistic arc since it isnt going to have a wide swing. If i can get this on a purely horizontal back and forth, diminishing movement it would be enough.

    This should do it: (make 200 pixel wide / 10 pixel tall actor).

    Constrain X to 100 x cos ((70-self.Time x 10) x sin (self.Time x 250)-90)+512

    Constrain Y to 100 x sin ((70-self.Time x 10) x sin (self.Time x 250)-90)+384

    Constrain Rotation to (70-self.Time x 10) x sin (self.Time x 250)-90

    And to stop the sin function carrying on once the swing has settled down - wrap the whole lot in a rule like this:

    Rule: When (70-self.Time x 10) is larger than > zero . . . . then do all the above.

    Not at my computer right now, I will check it all works as it should, but I'm petty sure that's all you'll need.

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2014

    An explanation:

    Rule: When (B-self.Time x D) is larger than > zero . . . . then

    Constrain X to A x cos ((B-self.Time x D) x sin (self.Time x C)-E)+ X pivot point

    Constrain Y to A x sin ((B-self.Time x D) x sin (self.Time x C)-E)+ Y pivot point

    Constrain Rotation to (B-self.Time x D) x sin (self.Time x C)-E

    A = Diameter of the rope (half of the longer dimension)

    B = Range of swing

    C = Speed of swing

    D = Life of diminishing arc.

    E = Angle offset.

  • SocksSocks London, UK.Member Posts: 12,822
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Tosanu‌ --

    You asked a very interesting (and novel) question!

    This is the first time that I can recall (in the four years I've been on this forum) that this question has been asked! In all other instances, questions have been about making a pendulum swinging movement -- but not how to make an actual pendulum that acts and reacts to the physics of other actors.

    So most (actually all) past answers have been about how to mimic the movement of a pendulum -- but not how to make an actual pendulum.

    There are some subtle differences between an actor that is swinging in an arc because it has been programmed to have pendulum-like movement, and an actor that is actually a pendulum. One of the differences is that a real pendulum should be able to bounce off of another actor (just like you asked about). That is, it needs to be a physical simulation and not simply a programmed series of pendulum-like movements.

    So.... even though you have decided not to use a pendulum, but instead are going to "use an illusion workaround based on interpolating," I'd still like to address your original question. It may not come up again for another 4 years!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited June 2014

    OK -- after some false starts I think I have a solution to how to do a physical simulation of a pendulum -- instead of a simulation of pendulum motion.

    The problem with previous solutions (including many of mine) is that we were just driving the motions of a pendulum, without actually using GameSalad's built-in physics engine. In other words, we were constraining rotation instead of letting GameSalads built-in physics determine a pendulum's rotation.

    This simulation calculates how much torque that gravity is feeding into the pendulum. Torque is the twisting motion exerted on an actor. I found a formula for torque here:

    http://hyperphysics.phy-astr.gsu.edu/hbase/torq2.html

    If we constantly add torque to the actor's current rotation velocity -- we get a form of rotational acceleration. Fun stuff!

    http://www.mediafire.com/download/w9u5579oaia2c57/torquePendulum.zip

  • SocksSocks London, UK.Member Posts: 12,822

    @RThurman said:
    OK -- after some false starts I think I have a solution to how to do a physical simulation of a pendulum . . . .

    Great ! :smile:

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Socks‌ -- There is great power in knowing how to recognize a key question.

  • SocksSocks London, UK.Member Posts: 12,822

    @RThurman said:
    Socks‌ -- There is great power in knowing how to recognize a key question.

    . . . and approaching cars :p

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Socks said:
    . . . and approaching cars :p

    . . . and the difference between physical simulations, or an animations, or actual approaching cars!

    Did you try the torquePendulum demo?

  • SocksSocks London, UK.Member Posts: 12,822

    @RThurman said:
    Did you try the torquePendulum demo?

    Yes, that's what I was referring to, it's great ! :smile:

Sign In or Register to comment.