playMaker

Author Topic: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?  (Read 1711 times)

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Hi All,

Hoping someone can help to shed some light on an issue I've been having for a while now.

I'm currently creating a 3D game for mobile with a 'vehicle' moving across a plane.

I've been using a movement system based upon a 'click/touch screen to set a target position' using Move Towards Advanced to move my gameobject and whilst it does work, it's never been 100% successful with regards to collisions. I've made sure that the finish distance is 0 and it runs on a fixed update.

I guess what I'm looking to see is if there is a way of doing this using a force-based rigidbody movement rather than a translate position. I have tried Add Force with an impulse set to the Z axis (self) but the results are always a bit odd - especially the way it can sometimes head off into space.

I did try and think of a way to run a "here's the position, now move here" but as a non-programmer, I can't get my head round it and sure I must be missing something obvious.

If someone can give a few pointers, I'd be incredibly grateful.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
    • View Profile
Re: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?
« Reply #1 on: July 16, 2017, 04:40:45 AM »
Have you considered using navmesh? That way it could go around obstacles.

I have a tutorial here that starts with how to make objects clickable with the mouse to select them, then goes into movement with move to, lastly I cover using navmesh to move instead:
« Last Edit: July 16, 2017, 04:46:17 AM by tcmeric »

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?
« Reply #2 on: July 16, 2017, 05:16:40 AM »
Thanks for that advice. Your video is really useful :D

My game does involve a lot of collisions with the 'tank' bumping into static colliders and crashing through building blocks, dominoes, toys, etc (one of the reasons why I'm looking for better collisions) and moving over a platform - would a navmesh allow for this?

I will have a look at that later today though and see if it'll integrate with what I have (which fingers crossed it could).

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
    • View Profile
Re: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?
« Reply #3 on: July 16, 2017, 06:36:48 AM »
I havent tried it, but maybe this would work. Put a colider on your tank. The gameobjects you want it to knock, make them not static (so they dont get covered in navmesh). Give them coliders. Then your tank should still path through them and knock them over in the process.

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?
« Reply #4 on: July 16, 2017, 09:07:17 AM »
Excellent!

I've been applying static markers for lighting purposes so no changes there.

I'll give this a try and post back the results later on.

bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?
« Reply #5 on: July 16, 2017, 01:29:16 PM »
I've had a look at the NavMeshAgent but sadly it's not quite as competent as the MoveTowardsAdvanced setup I currently have. I've tried looking at pathfinding to see if I was missing out on anything but I think it's more complicated than I can get my head round at this time.

MoveTowardsAdvanced is pretty good when it comes to ramps, collisions with rigidbodies and bumping into obstacles with a physic material applied - it's just that it has a habit of slipping through the mesh where 90 degree corners meet or any box colliders which aren't on a level plane. It's also great for tracking a constant touch/click and drag on the screen when used with a 0 finish distance.


bazzajunior

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
    • Molber Games
Re: Can I use 'Add Force' instead of 'Move Towards Advanced' (3D game)?
« Reply #6 on: July 18, 2017, 07:30:21 AM »
Just an update for those who may find themselves in a similar predicament to mine - using a translated rigidbody rather than one moved by force. I found that by keeping the move towards advanced running with a 0 finish distance and a fixed update, by setting the project time (fixed timestep) to 0.005, this allows Unity to keep a better track of the colliders and remove some of the dodgy collisions.

In my particular instance, my game object is no longer slipping through a mesh where a 90 degree angle is in place or where two meshes (both static) may have resulted in a pass-through.

It's not true movement by the use of physics but it does work :)