Sunday, 26 October 2014

Further work into new physics setup

Ok, so carrying on from the post below, I attempted to re-orient vehicle, (or rather, what will be a block to simply calculate weight of the vehicle and handle player input) based on the impact normal of a ray trace.

Ended up getting largley stuck on it over the weekend, and even ended up making a help request on the UE4 answer hub to see if I could gain any insight into how to do this. Though sadly the advice I was given wasn't very helpful, as it produced the same results as I was already getting. The character would re-orient correctly in one direction, ie. It would look up a slope, but maintain the rotation when looking down the slope.



(UE4 Answer Hub thread)



Whilst the assistance I got wasn't helpful, I did end up having a eureka moment.

The whole point of using a single ray trace was twofold, one it would cut down on the total number of raytraces I was drawing (7 off the old physics model), But also to lower the number of physics calculations that were being performed (5 that interacted with the ray traces) with the aim to improve performance (cpu wise) as well as vehicle handling)

The other reason was that the old suspension to keep the vehicle stable had to  apply the force at a very large offset from the vehicle itself, meaning it would push itself off the walls of the track whenever it went near them. Having a singular upwards force at the center of the vehicle and using rotators to stabilize it would solve this problem.


My idea was fairly simple, to create a small array of ray traces in a cross formation which simply fed back no other information,than the world space location of the hit.

I could then use them to feedback rotation information, by taking the direction vector from eg. The rearmost raytrace impact and the forwards most impact point, to produce what I could use as my new x axis. and vice versa for left -> right.


It wasn't entirely simple to work out and I ran into a bunch of complications along the way, for a long period the vehicle would lock to a specific axis of the surface it was on, but only on an angled slope. The original model that was causing this I later realised was retrieving the local impact location of the ray traces which was causing confusion in the rotators.

It also originally just combined the two rotation outputs. where only one of them took yaw information from the hull. I later realised that it would be a lot simpler to create one rotator and add the individual axis values together.

When the system was finished and working I threw a Rinterp to lower out the speed at which the rotation happened and make any accidental bumps in the road surface less noticeable by producing a smoothing effect.



No comments:

Post a Comment