playMaker

Author Topic: Rolling a Ball [solved]  (Read 6204 times)

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Rolling a Ball [solved]
« on: July 10, 2011, 03:41:26 PM »
Bah.  I need help again.

I am rolling a ball in my game.  The player is a normal, bipedal character controlled through the PlatformInputController and CharacterMotor scripts.  The player needs to "push" the ball in front of them.

For the ball I am using a sphere with a really high Drag value (so it stops immediately), and applying forces to the ball.  My problem is that I can't get the vector right.  Since this is a rolling object axes are prone to rotation, so local coordinates aren't reliable for applying a force.  What I would like to do is simply apply a force relative to the games camera, however I cant figure out the combination of transforms and calculations in order to get that vector, transform it to world-space, and apply it to my sphere.

As always, help is MUCH appreciated!

« Last Edit: July 12, 2011, 05:52:29 PM by artician »

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Rolling a Ball
« Reply #1 on: July 11, 2011, 11:33:46 PM »
doesnt your character controller collision simple cause the ball to roll when you walk into it if you apply a sphere collider to the ball?


artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Rolling a Ball
« Reply #2 on: July 11, 2011, 11:54:47 PM »
Man, I wish.  Unfortunately the player just bounces against it/over it.  The ball does not budge.

Here's the deal - I've been working on this one problem off and on for several weeks.  I have tried every conceivable workaround with no satisfactory solution.  Every attempt is 99% of the way there, with that last missing bit being a game-breaker.  

I've been looking at this far too long, so I'm going to go take a nice long nap, and when I wake up I think I will spend most of tomorrow compiling all the different things I've tried and presenting them to the forum to see what people think.  For the time being I've tried everything from character controller collision, to direct translation of the player object, to proxy colliders, to emitting physics forces from every conceivable player-orifice, to parenting objects and then animating children to simulate rolling motion... on and on and on.  I'll laugh pretty hard if there's a checkbox somewhere that makes it all work, but I am confident that's not the case. ;)

Thanks for the reply.
« Last Edit: July 11, 2011, 11:56:21 PM by artician »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Rolling a Ball
« Reply #3 on: July 12, 2011, 12:51:15 AM »
Are you using the CONTROLLER COLLIDER HIT event and the Get Controller Hit Info action?

Seems like you could use the Move Direction to push the ball around...


artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Rolling a Ball
« Reply #4 on: July 12, 2011, 04:00:10 PM »
Quote
Seems like you could use the Move Direction to push the ball around...

I didn't think it worked in that way, but I spent this morning trying it and it does not.  Ball is still stationary.

Here is a list of things I have tried:

Parenting -
I spawn and parent the ball to a 'holder' object just in front of the player.
Because there is no angular velocity when this is done, I have a child-object rotate to represent rolling.
Speed and angle are derived from the player.
Parent ball is used for collision against slopes.

Result: This works the best, however I have to manually adjust the 'holder' object as the ball grows in size (player is rolling snowballs), and it gets quite finicky.  Additionally, the ball rolling animation is not very good, as I have to roll on different axes in order to avoid the ball looking in the direction of it's rotation.
This is what I will fall back to if all else fails, because it still works for gameplay.


Force Driven -
Ball is spawned in front of player.
Player has a trigger volume attached and positioned in front of it.
When the ball enteres the trigger, a force is applied.

Result: No amount of drag or force value will let the ball move forward smoothly, remaining near player and not being kicked out of range.  This just took too much tweaking to make it worth it.  Physics are like that.  Stupid physics...

Direct Translation -
Spawn ball in front of player
Make player LookAt ball at all times in this state.
Get Horizontal and Vertical Axes
Using the axes values, moderate between moving forward or rotating around the ball to change direction.

Result: The character controller will push the ball PERFECTLY using this method, however due to the direct manipulation of the player transform, the character controller no longer responds to environment collisions, and can be rotated through walls or walk through slopes.  This would be my favored method if I had an easy way to write a collision script from scratch.  (Open to alternatives!  I'm certain I missed something in this method).

There were a few other things I attempted that aren't worth mentioning, mostly because they weren't ways I wanted the game to go.  Thanks for reading and offering any ideas.  I'd love to know if one of these methods should work as intended also.  I am seriously mentally fatigued from this particular aspect of my project.


artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Rolling a Ball [solved]
« Reply #5 on: July 12, 2011, 05:54:19 PM »
Ultimately Alex's suggestion worked out okay.  I had to use a collider that was significantly larger than the player CharacterController, but it alleviated the collision glitches I was getting.  Then I was able to rescript some of my other mechanics so they didn't interfere with the new collision volume in their space.

Thanks guys.  It turns out this was more of a Unity issue than a PlayMaker one, sorry to waste time.