playMaker

Author Topic: how can I change gravity so my NPC can walk on walls?  (Read 15700 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 268
how can I change gravity so my NPC can walk on walls?
« on: December 03, 2013, 03:01:33 PM »
Hi,
I have a cave, that a NPC can freely roam and jump around. How can I get him to jump onto a wall, or the ceiling and land on his feet, then walk around as if he is still on the ground. Or I suppose what I'm asking is, how can I get him to walk on a sphere, keeping upright and on his feet?

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #1 on: December 03, 2013, 03:04:33 PM »
Oh also, I want to transition between each jump, so say if he decides to jump from the ground to the wall, I need him to rotate when he gets closer to the wall, so his feet land first.

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: how can I change gravity so my NPC can walk on walls?
« Reply #2 on: December 03, 2013, 11:53:21 PM »
I'm sure there's a way to redirect the effect of gravity on a character's acceleration (and therefore direction) via Playmaker or scripting but I had an idea:

Why not just rotate the scene around the player? The camera could also rotate with the level, or stay stationary depending on what you're going for.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how can I change gravity so my NPC can walk on walls?
« Reply #3 on: December 04, 2013, 04:47:46 AM »
Hi,

 another way woul dbe to have your NPC not affected by gravity and simply add a force downward itself, Gravity is only a constant force, so faking with a custom force it is totally fine!

bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #4 on: December 04, 2013, 10:06:18 AM »
Hi, thanks for the help.  I don't want to rotate the camera as it's for a NPC.
Jean, that sounds like something I'll need to do, but what about using a off mesh link so the NPC can jump between the two?
So, first is it possible to use a navmesh that runs along walls, ceilings etc? And second, if I can get the NPC to jump to another mesh, how do I make him stay vertical to whatever terrain he walks on?
Basically, I want him to be able to use the navmesh to walk around terrain that has walls and ceilings and for him to stay perpendicular to the surface he walks on.
Thanks for any help.

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59
Re: how can I change gravity so my NPC can walk on walls?
« Reply #5 on: December 04, 2013, 06:05:18 PM »
You probably want to raycast downward from your NPC and use the normal from whatever surface the raycast hits.

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #6 on: December 06, 2013, 01:15:50 PM »
You probably want to raycast downward from your NPC and use the normal from whatever surface the raycast hits.

Thanks for your help.  So, Raycast down every frame, use Vector3 Normalize from the terrain?  Is that what you mean?

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59
Re: how can I change gravity so my NPC can walk on walls?
« Reply #7 on: December 08, 2013, 02:59:45 AM »
No I mean, use the normal returned from the raycast hit. This is how you will correctly orient your NPC to whatever surface it's travelling on :)

Jean provides a working example of a similar issue (creating and orienting bullet hole decal) in this thread:
http://hutonggames.com/playmakerforum/index.php?topic=725.0

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #8 on: December 08, 2013, 01:17:10 PM »
Ah got it thanks for your help

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how can I change gravity so my NPC can walk on walls?
« Reply #9 on: December 09, 2013, 03:03:38 PM »
Hi,

 Also, you can study this sample, which is a simple example of how gravity can be affected to have your character walk on abstracted gravity definition.

https://trello.com/c/ualFozZg/1-physics-character-gravity-based-on-ground-normal

bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #10 on: December 28, 2013, 01:12:30 PM »
Hi,
Jean, the GroundBasedGravity package is good but I need it checking the terrain every frame so it can rotate whenever it hits a slope.  I've attached a pic of a cube on terrain as an example of what I'm after.  Can you help get started?

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #11 on: December 29, 2013, 09:48:11 AM »
I've used the RaycastFromGameObject and it looks like it works, except my gameobject is rotated on its side as it moves over the terrain. I have a simple hill, that my object moves over and as it reaches the top, it rotates.

So, just having another look at it,  as it moves torward the destination, the forward axis (z) points upward and the (y) points forward up the hill, then backward going down the hill.  What am I doing wrong?
Please help  :-\

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how can I change gravity so my NPC can walk on walls?
« Reply #12 on: December 29, 2013, 12:53:37 PM »
Hi,

 Can you bump this in few days? Thanks, I'll do a working sample then.

 Jean

Bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: how can I change gravity so my NPC can walk on walls?
« Reply #13 on: January 01, 2014, 08:24:23 AM »
Hi,

 Can you bump this in few days? Thanks, I'll do a working sample then.

 Jean

Bye,

 Jean

<bump>

thanks Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how can I change gravity so my NPC can walk on walls?
« Reply #14 on: January 03, 2014, 05:43:02 AM »
Hi,

 Ok, I have attached a package that will show how to apply gravity to a rigidbody based on the mesh it evolves on.

warning: You mentionned in your pm that you wanted to use navmesh, I don't think navmesh will work with changing gravity, just like built in character controllers assume a constant gravity direction ( for jumping typically).

So, you may have a problem of integration between a changing gravity situation and controlling your character or navmesh.

One way I would consider to get away from this issue is to have your mavmesh invisible and only acting as a dummy position for you to follow and then align vertically to the current terrain normal. That would work I think.


Bye,

 Jean