SphereCharacterController request move to position
Posted: Tue May 03, 2016 7:27 pm
Hey there!
First of all, thank you so much Ross for the awesome engine. In the last weeks I've implemented it into my simple isometric 3d rpg/hack&slash game without any problems. Works like a charm. However I've stumbled upon a problem recently, and I just cant find a solution. Here's the story.
For npc's and player I am using SphereCharacterController. Most of the time, player is moved around using keyboard input, and the npc's are following the paths calculated by A*. For that part, it all works perfectly, updating the controller each frame like this:
However, there are cases, when the movement of a player or npc must be controlled by the animation (when performing special combo attacks for example), so that move dir and ammount perfectly fits animation. I am doing it by appending the animation root bone position change to position each frame like so:
So basically, I need a way to tell SphereCharacterController/HorizontalMotionConstraint to try to move to a specific position (or for a specific vector) each frame, but I simply cannot figure out how to do so. I do not want to reinvent the wheel here, as SphereCharacterController otherwise perfectly fits my needs and would like to stick with it.
The only idea I came up with was recalculating the speed each frame when animation is controlling the movement:
But I do not know how to scale the speed (SpeedScale), since I guess it should consider many factors like char mass, traction, etc...??
I know I could teleport the char to the desired position by setting it's Body.Position, but then I'd loose all the collision response, which I still need as normally, even when animation is controlling the movement.
Please help me out!
Thanks a lot!
Regards,
Uros
First of all, thank you so much Ross for the awesome engine. In the last weeks I've implemented it into my simple isometric 3d rpg/hack&slash game without any problems. Works like a charm. However I've stumbled upon a problem recently, and I just cant find a solution. Here's the story.
For npc's and player I am using SphereCharacterController. Most of the time, player is moved around using keyboard input, and the npc's are following the paths calculated by A*. For that part, it all works perfectly, updating the controller each frame like this:
Code: Select all
CharController.Speed = FixedCharSpeed;
Char.HorizontalMotionConstraint.MovementDirection = CharDirection;
Code: Select all
Position = Position + AnimPlayer.RootBoneDeltaMove;
The only idea I came up with was recalculating the speed each frame when animation is controlling the movement:
Code: Select all
CharController.Speed = AnimPlayer.RootBoneDeltaMove.Length() * SpeedScale;
Char.HorizontalMotionConstraint.MovementDirection = Vector3.Normalize(AnimPlayer.RootBoneDeltaMove);
I know I could teleport the char to the desired position by setting it's Body.Position, but then I'd loose all the collision response, which I still need as normally, even when animation is controlling the movement.
Please help me out!
Thanks a lot!
Regards,
Uros