Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Splankton on December 03, 2013, 03:01:33 PM

Title: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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?
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Breadman 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.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre 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
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: uberwolfe 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.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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?
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: uberwolfe 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
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on December 08, 2013, 01:17:10 PM
Ah got it thanks for your help
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre 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
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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?
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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  :-\
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre 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
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton 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
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre 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
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 03, 2014, 07:31:52 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

Ok, thanks for your help :)
I've gone back to basics and just trying to get a cube (as its closest to the object I want) and just moving it in playmode over my terrain.  If I just leave the gravity problem for a moment, how can I just set my cube to rotate to the normal of the terrain?
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 03, 2014, 10:14:00 AM
Have a look at the attachment, it shows a cube sitting on the terrain. My goal is to move my object from say A to B, adjusting the objects rotation, by getting the normal from the terrain.
I understand I'll have to dummy the navmesh, but for now I just want to position the cube onto that terrain and have it rotating itself so it "hugs" the terrain.
I'll worry about the navmesh problem later. 
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: fromfame on January 05, 2014, 10:52:14 PM
Yep, what Jean said about faking things in general saves a lot of work, once I made a huge clock tower with hundreds cogs that actually moved through physics, it doesn't look good but hey it was real?

I achieved nothing lol I should've just faked it.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 06, 2014, 07:12:35 AM
Well at the moment I have the navmesh inside an empty gameobject as the parent, then my character as a child, using the raycast to get the normal.  I have it moving from A to B, but there is no rotation from the normal. What am I missing?
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre on January 07, 2014, 04:39:31 AM
Hi,

 ok, that starts to shape in my mind a bit better, I'll work on a sample, basically with a dummy on the floor moving around and a object following that fummy position but aligning itself to whatever it is grounded too, I think this will the right setup.

and ion this case, it's not anymore a question of apply a different gravity, but more a per NPC ground alignment not using physics at all.

bye,

 Jean
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 07, 2014, 08:11:00 AM

So if I have my moving object as a rigidbody, and use kinematic, I won't need to apply a constant downward force to keep it stuck on the ground, even if the object is on a wall or ceiling?

Thanks again Jean, I look forward to your example.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre on January 10, 2014, 07:13:40 AM
Hi,

If your RigidBody is set to Kinematic than forces have no effect, so indeed no need to apply forces at all.

bye,

 Jean
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 10, 2014, 07:41:45 AM
Hi,

If your RigidBody is set to Kinematic than forces have no effect, so indeed no need to apply forces at all.

bye,

 Jean

Ok thanks for clearing that up :-)
I still can't get my object to adjust it's rotation from the normal.  How's that working sample going?
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre on January 10, 2014, 08:05:31 AM
I should have the time next week, currently, I trying to clear the pending threads and unreplied posts on the forum.

bye,

 Jean
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 15, 2014, 11:55:45 AM
I should have the time next week, currently, I trying to clear the pending threads and unreplied posts on the forum.

bye,

 Jean

Ok thanks Jean. I thought I may have fixed it by then, but still having trouble. I think I need to use quaternian to get the proper rotation. But I maybe totally off track.
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 22, 2014, 05:03:40 PM
Still can't do it. Jean let me know when you get time. Thanks
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: Splankton on January 28, 2014, 03:20:13 PM
<bump>
Title: Re: how can I change gravity so my NPC can walk on walls?
Post by: jeanfabre on January 31, 2014, 06:28:32 AM
Hi,

 Here we go, have a look at this, this should give you all you need.

 basically, The actual controller stays vertical, but attached to it is a special "Orientation" gameobject that will conform to the normal of the floor and your visible character simply has to be a child of that "Orientation" dummy.

bye,

 Jean
Title: Re: how can I change gravity so my NPC can walk on walls?[SOLVED]
Post by: Splankton on January 31, 2014, 02:35:52 PM
Hi,

 Here we go, have a look at this, this should give you all you need.

 basically, The actual controller stays vertical, but attached to it is a special "Orientation" gameobject that will conform to the normal of the floor and your visible character simply has to be a child of that "Orientation" dummy.

bye,

 Jean

Thanks a lot Jean!
I have applied it to my model and it looks like it works.
I had a small problem with the rotation of the model when it was aligning to the ground, but I fixed it by setting the rotation to 270x and 180y.
So before it starts checking the normal, the model is upside down and rotated, but works great as soon as your FSM is active.  So thanks again Jean!