- Home /
Predict Charactercontroler movement
Hey guys, I want to predict where my Character would be half a second in time if he continues on his current path. But I am unsure of how to simulate the game X frames into the future. I cant just apply the current velocity of the character X frames worth of times, because if the character goes over a hole, he would have to fall in. any suggestions?
You should have your velocity based on Time.deltaTime
so that the character's velocity is independant of the frame rate. Then you can just calculate it based on the Physics formula (from high school): v = d / t
. You could shoot a raycast through the ground (ignoring the ground, of course) for the distance the character would travel to see if there are any holes they might fall into.
its a platformer, so the 'holes' are the edge of platforms. i dont see how that would work. that is - the characters 'edges' might collide with the platform, stopping him from falling. shooting a ray down wouldn't work properly.
Answer by Ipsquiggle · Jun 19, 2012 at 03:50 AM
If you are using the Unity physics system, this is quite a tricky problem. As you say, you'd have to simulate future frames, but as there is no direct manipulation of the physics system, there's no easy way to tell it, "Simulate this again! and again! and again!".
There are two possibilities in front of you, depending on whether you need a precise "location" of the character or just an idea of the environment around him:
1
If your physics needs are fairly simple, do the simulation yourself. Applying forces, velocities, and simple collision handling (you can still use the physics system for collision testing, with shape-casts!) is reasonably straight forward. Then you could just query your own system in whatever way you please to calcuate future frames.
2
This is probably the easier answer, but less accurate: Build up a set of "tests" using shape-casts and traces for the future position, e.g.
Is there open path ahead?
Is there a wall ahead?
Is there a hole ahead?
etc.
You will not get a perfectly precise position (so you couldn't, say, "show the player" where he's going to be in 1 second), but depending on your needs, you would probably be able to tell "things" like, "The character is about to fall in a hole!" and have it behave accordingly.
ended up doing idea 2, yeah. didnt need to 'simulate' the whole path it turns out. just getting an accurate idea of what is ahead was good enough.
Your answer
Follow this Question
Related Questions
How should I check if the charactercontroller is grounded next in the next calculation? 1 Answer
‘CharacterController’ does not contain a definition for ‘Move’ 0 Answers
Character controller Skin width no effect 0 Answers
Character Controller collision 1 Answer
[SOLVED] Character Controller moving at different Framrates? 4 Answers