playMaker

Author Topic: Pulling Objects [SOLVED]  (Read 2435 times)

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Pulling Objects [SOLVED]
« on: January 26, 2014, 06:55:16 PM »
My character has the ability to push and pull different large objects to solve puzzles (similar to Zelda games). Pushing works fine using some basic physics and rigidbodies - I found a script called "pushforce.js" which works quite nicely and is super simple.

Pulling is proving more challenging to implement. I made an FSM which, when shift is pressed, searches for the nearest tagged object and parents it to the character (also causes the character to face the object while moving). This achieves the pulling effect, but rotating the character also rotates the object based on the character's axis, so the object starts swinging around.

I'm wondering if there's a method other than parenting the object to the character. I tried "reversing" the push script by adding a -1 multiplier, but that caused strange results. Is there some sort of method for adding a pull force, towards the center of my character, during a state? Perhaps some sort of gravity?

Just trying to feel out a solution for this, if any of you guys have any ideas I'd be so thankful!
« Last Edit: January 26, 2014, 07:17:33 PM by Breadman »

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Pulling Objects
« Reply #1 on: January 26, 2014, 07:14:12 PM »
I managed to get it working with "move towards", moving the nearest cube towards the player. I set the target distance to 0, so that the FSM remains in this state and continues to move the cube towards the player, until shift is released. However, this causes the cube to jitter significantly. I'm wondering if there's a way to reduce this jittering as the cube continues to move towards the player?

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Pulling Objects
« Reply #2 on: January 26, 2014, 07:17:22 PM »
Found a solution -

Created an empty gameobject named "pullpoint", parented it to the character controller and placed it about half-a-cube's width away from the character, so the cube will appear as though its edge is moving towards the character, but really, the cube's center is moving towards an invisible point slightly away from the character. Yay.