• Advertisement
Sign in to follow this  

Unity Player movement without physics engine

This topic is 1242 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm curious as to what sort of techniques exist for handling player movement in a 3D environment without the use of a physics engine.

 

One approach I've tried in the past was using sphere casting (performing multiple iterations to handle sliding), but it had a number of quirks that I couldn't easily resolve.

 

Another thought I had was to just move the player along a navmesh, as described in http://digestingduck.blogspot.com/2010/07/constrained-movement-along-navmesh-pt-3.html. The main thing I'm still unsure about is how to handle dynamic obstacles (ex. enemies). And most of the navmesh resouces I've found so far pertain to the implementations in Unity, Unreal, or Source, rather than how to actually implement it.

 

Any thoughts on the above or alternative techniques? Or good resources on implementing them?

 

Also, are there any commercial games using similar approaches? From the small amount that I've played it, I think Kingdoms of Amalur: Reckoning might be using an approach similar to the second one I described, but I'm not sure. 

Share this post


Link to post
Share on other sites
Advertisement

..without the use of a physics engine.

 

First, a little clarification - the various types of things you describe are better termed path-finding, collision engines or collision detection. Physics engines normally deal with object mass, velocity, angular velocity, etc., and the responses to collisions, which doesn't sound like what you're talking about.

 

Second, the topic title is "Player movement.." Do you mean a player guided by a user, or NPCs, perhaps guided by AI?

 

As it seems you're asking about collision detection, I suggest you look into the Bullet or ODE (Open Dynamics Engine) libraries, both of which implement collision detection, and (IIRC) can be setup to use the collision detection parts separate from the physics parts.

 

With regard to collision detection techniques, there is also raycasting (also implemented by Bullet and ODE, BTW), which is a technique for specifying a position and direction (a "ray") and calculating intersections with various geometries. That technique could include spheres or capsules representing "dynamic" objects moving about.

 

You could also look into "sweep and prune" or "swept volumes."

 

Without details of your needs, it's difficult to provide more specific information.

Edited by Buckeye

Share this post


Link to post
Share on other sites

Are you referring to perhaps games like diablo, where the movement of the player is abstracted?  In a diablo style game, technically you don't need a physics engine, the player character just moves to wherever a valid click is, so essentially the pathfinding is doing all the work to guarantee there are no collisions.  (it still has to check for collisions, but there would be no collision response)

Share this post


Link to post
Share on other sites
Let me see if I can explain this better. I'm looking for approaches for controlling the movement of a player character (guided by the user), that do not use a physics engine (using the collision portion of Bullet is fine). So a non-physical or non-dynamic character controller, which would seem to be considered a kinematic character controller? (Though I'm not sure if the second approach below would be considered a kinematic character controller)
 
1. The approach that I have attempted to implement in the past used only the collision portion of Bullet to perform sphere-casts against a triangle mesh representing the world. So it calculates how far a sphere can move in a certain direction, and if that distance is less than the desired movement direction, it then projects the movement vector onto the surface that was hit, and performs another sphere-cast to allow for sliding collision. It might repeat that a couple times depending, and also does another sphere-cast in the vertical direction to handle y-velocity and stepping-down (to avoid floating/bouncing while moving down an incline. I believe that was also used to determine whether the player was standing on the ground. There were a number of issues that I ran into with this approach including getting caught when sliding along certain geometry, jittering in obtuse corners, and bouncing along the edge between the ground and a surface that is considered to steep to walk on.
 
2. The other approach is one that I have not attempted to implement yet. It would involve using a navmesh similar to what would typically be used to handle NPCs, except for the player. This is a slightly more limiting than #1 in that the player is constrained to the navmesh. Even though the player could jump, they could not, say, jump across the edges of the mesh (ex. over the edge of a staircase back to the floor). They basically move around within a triangulated 3D polygon. There would be no real collision detection between the player and the world geometry. One of my current uncertainties with this approach would be the handling of other obstacles (ex. enemies moving around).
 
So I'm wondering:
  • Are the above approaches actually used?
  • What other approaches exist?
  • Are there any good resources on implementing these approaches robustly?

 

 

Rough sketch of #2

[attachment=24007:second.png]
 

Share this post


Link to post
Share on other sites
Very often there are multiple sets of data. The physics ground is one object, the rendered terrain is a second object, and the navigation mesh is another.

A navigation mesh can be very simple, even a 2D grid that maps onto the terrain. It can also be complex, a full triangulated mesh or even a volumetric representation.

Games will often have multiple parallel representations internally, a fact often surprising to new developers.

I've worked on several games that people think of as bigger 3D worlds but in reality were just 2D grids internally; height is just stacked grids starting at ground level. Players move from cell to cell to cell, animating smoothly along the way. A tiny bit of animation magic and the walked paths can bend and twist organically over the 2D grid yet still move from cell to cell.

Motion is only allowed between areas of a navigation mesh if the two sides are connected. Disconnected edges, like the ramp in your image, are not navigable. They act as a wall or barrier.

What you drew in your image is a great example of a navigation mesh. It isn't a physics mesh since you don't want things to fall off it. It isn't a render model since your stair will will likely have a rail or other barrier. Many times they will have additional information tied to the nav mesh to indicate things like sounds and speed and other attributes (e.g. walking on wood, walking on carpet, splashing over puddles, squishing through mud, etc.)

For your other questions... Yes, they are extremely common. To make them fast people usually break them up with spatial trees, and most of the big articles about loose quadtrees and such are intended for use in navigation meshes with things (like enemies) moving around. There are lots of articles about the subject, you just need to realize what you are looking at. For alternate implementations, you can rely entirely on physics for some games (Super Monkey Ball comes to mind) and you can rely on strict grids for things like board games, but nav meshes with spatial trees over the navigation mesh is really the standard method.

Share this post


Link to post
Share on other sites

Jeff

 

1.  This method seems like you're basically doing your own form of collision response.

2.  This method seems like the diablo method I mentioned before.  I've implemented variations of it.  It was pretty trivially easy to for example, get a the ray from a click on the screen, find where it hits the navmesh and then have the player-actor try to navigate to that point on the navmesh.  You are correct that jumping doesn't work with that method, one would either need to have jump as connector node type thing(Aliens the RPG was going to use something like this, if I recall correctly) or make jumping physically driven.   Oh, and for enemies and other moving characters, usually a form of local avoidance is used.

Edited by ferrous

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By Manuel Berger
      Hello fellow devs!
      Once again I started working on an 2D adventure game and right now I'm doing the character-movement/animation. I'm not a big math guy and I was happy about my solution, but soon I realized that it's flawed.
      My player has 5 walking-animations, mirrored for the left side: up, upright, right, downright, down. With the atan2 function I get the angle between player and destination. To get an index from 0 to 4, I divide PI by 5 and see how many times it goes into the player-destination angle.

      In Pseudo-Code:
      angle = atan2(destination.x - player.x, destination.y - player.y) //swapped y and x to get mirrored angle around the y axis
      index = (int) (angle / (PI / 5));
      PlayAnimation(index); //0 = up, 1 = up_right, 2 = right, 3 = down_right, 4 = down

      Besides the fact that when angle is equal to PI it produces an index of 5, this works like a charm. Or at least I thought so at first. When I tested it, I realized that the up and down animation is playing more often than the others, which is pretty logical, since they have double the angle.

      What I'm trying to achieve is something like this, but with equal angles, so that up and down has the same range as all other directions.

      I can't get my head around it. Any suggestions? Is the whole approach doomed?

      Thank you in advance for any input!
       
    • By devbyskc
      Hi Everyone,
      Like most here, I'm a newbie but have been dabbling with game development for a few years. I am currently working full-time overseas and learning the craft in my spare time. It's been a long but highly rewarding adventure. Much of my time has been spent working through tutorials. In all of them, as well as my own attempts at development, I used the audio files supplied by the tutorial author, or obtained from one of the numerous sites online. I am working solo, and will be for a while, so I don't want to get too wrapped up with any one skill set. Regarding audio, the files I've found and used are good for what I was doing at the time. However I would now like to try my hand at customizing the audio more. My game engine of choice is Unity and it has an audio mixer built in that I have experimented with following their tutorials. I have obtained a great book called Game Audio Development with Unity 5.x that I am working through. Half way through the book it introduces using FMOD to supplement the Unity Audio Mixer. Later in the book, the author introduces Reaper (a very popular DAW) as an external program to compose and mix music to be integrated with Unity. I did some research on DAWs and quickly became overwhelmed. Much of what I found was geared toward professional sound engineers and sound designers. I am in no way trying or even thinking about getting to that level. All I want to be able to do is take a music file, and tweak it some to get the sound I want for my game. I've played with Audacity as well, but it didn't seem to fit the bill. So that is why I am looking at a better quality DAW. Since being solo, I am also under a budget contraint. So of all the DAW software out there, I am considering Reaper or Presonus Studio One due to their pricing. My question is, is investing the time to learn about using a DAW to tweak a sound file worth it? Are there any solo developers currently using a DAW as part of their overall workflow? If so, which one? I've also come across Fabric which is a Unity plug-in that enhances the built-in audio mixer. Would that be a better alternative?
      I know this is long, and maybe I haven't communicated well in trying to be brief. But any advice from the gurus/vets would be greatly appreciated. I've leaned so much and had a lot of fun in the process. BTW, I am also a senior citizen (I cut my programming teeth back using punch cards and Structured Basic when it first came out). If anyone needs more clarification of what I am trying to accomplish please let me know.  Thanks in advance for any assistance/advice.
    • By Yosef BenSadon
      Hi , I was considering this start up http://adshir.com/, for investment and i would like a little bit of feedback on what the developers community think about the technology.
      So far what they have is a demo that runs in real time on a Tablet at over 60FPS, it runs locally on the  integrated GPU of the i7 . They have a 20 000 triangles  dinosaur that looks impressive,  better than anything i saw on a mobile device, with reflections and shadows looking very close to what they would look in the real world. They achieved this thanks to a  new algorithm of a rendering technique called Path tracing/Ray tracing, that  is very demanding and so far it is done mostly for static images.
      From what i checked around there is no real option for real time ray tracing (60 FPS on consumer devices). There was imagination technologies that were supposed to release a chip that supports real time ray tracing, but i did not found they had a product in the market or even if the technology is finished as their last demo  i found was with a PC.  The other one is OTOY with their brigade engine that is still not released and if i understand well is more a cloud solution than in hardware solution .
      Would there  be a sizable  interest in the developers community in having such a product as a plug-in for existing game engines?  How important  is Ray tracing to the  future of high end real time graphics?
    • By bryandalo
      Good day,

      I just wanted to share our casual game that is available for android.

      Description: Fight your way from the ravenous plant monster for survival through flips. The rules are simple, drag and release your phone screen. Improve your skills and show it to your friends with the games quirky ranks. Select an array of characters using the orb you acquire throughout the game.

      Download: https://play.google.com/store/apps/details?id=com.HellmodeGames.FlipEscape&hl=en
       
      Trailer: 
       
    • By khawk
      Watch the latest from Unity.
       
  • Advertisement