I have looked at the motion path tutorials and how they make a spatial follow a path .But if the spatial has a physics control attached to the physics space ,it wont follow a thing.
Is there any way of making a physical spatial follow a path?

Yes. Apply forces to the physics spatial to guide it along the pathâ€¦

â€¦or switch the physics off for it if you really do want it just following the path no matter what.

I can make a physical spatial follow a path by setting its walkdirection to : wayPoint(index).subtract(currentPosition) while increasing the index when a waypoint is reached without using a motionpathlistener.
but when i set a vehicle linear velocity to such a vector ,the car just springs away .Should i really use linear velocity ,or i should use something else.

MonkeyZone has code that steers the car.

@normen ,thanks for the great news but i know nothing about the monkey zone?

So why didnâ€™t you enter â€śmonkeyzoneâ€ť in some search field here? Its an example game, check the wiki.

@normen ,now i came across a manualvehiclecontrol class which i applied to my car as a custom control plus i have keyinputs mapped to steer my vehicle .Now upon running my app ,my car just sits there, if i accelerate ,my car reverses ,if i apply a brake force, my car moves forward and upon releasing each key ,the car goes back to its start position .Now i havent looked much into the code but im guessing it has to do with the forces that i applied to the car being countered in the prePhysicstick method to prevent the car from colliding or is there something else i need to do? am kindly requesting help.

Well you will have to adapt the code to fit your use case. Also if you want the car to move by itself you should probably look at https://code.google.com/p/monkeyzone/source/browse/trunk/src/com/jme3/monkeyzone/controls/AutonomousVehicleControl.java

@normen ,wow that code was amazing,only a genius can come up with code like that ,was highly impressed with the way my car would steer itself and even reverse to make sure it passed through every way point .Increasing the anglemuit value ensured that it steered enough and increasing the checkRadius reduced the distance the car had to move toward a waypoint so that i could set higher speedmult values to increase the speed ,thanks for the great help

1 Like

now i have a situation where my vehicle drives straight to the next way point regardless of its enviroment .At times ,it would just get stuck trying to drive through a wall .so i was looking to make it avoid such collisions by implementing some of the code in manualvehiclecontrol class method prePhysicsTick, so before i use any of my exhausted effort ,i would like to know if this will help?

Just set the waypoints so that theres no walls between them? Many games also just reset the car to the closest waypoint when it doesnâ€™t move much in a certain time despite trying to get forward.

Well i worked on my waypts ,i only experienced such problems only on curvy tracks where the car would drive smoothly in the first lap the in the second lap where it comes in at different positions would have a higher chance of losing its way or when another vehicle twists it,and it would reverse onto a wall to find a missed waypt ,so i generally dont need to make it avoid collisions in that way?

Sure you can add additional code for some situations but Iâ€™d first try optimizing the values for the normal waypoints. Try to see what the actual issue is when it loses the way like that.

Well the original problem was the car would at times miss a waypt after colliding with another car then it would reverse to wall at times trying to go back to that pt ,now i only reset its position after it collides with the wall,if its velocity is less than 5, using the physicscollision listener ,it worked most of the time but at times ,the car would steer itself back to the wall ,collide ,be reset to last pt,steer to wall,now im not sure why it would do that and i dont think changing my waypts will do anygood cause i watch the car drive through all the waypts for about three laps before i put other cars,is there another way through this?

Sounds like you need more waypoints, so it always heads towards the center of the road.

Or more advanced logic to head back to the route once its jostled out of it.

@zarch ,you probably right ,cant believe i coulnt think of adding another waypt when that was what i had been doing,and am realising one of my problems was probably a compile time error as the engine was using up to 800mb ram ,and giving me not enough memory to compile errors,where the car would be reset and still get stuck. Now i have another issue where the car drives back to a missed checkpt and am wondering if i can use ifs to compare the distance to a forward waypt with the missed one ,or there are some useful vehicle properties like getMotionState i dont knw how to use ,that i can play around with.