CharacterController body speed, impulse and force

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
nikolaiko
Posts: 43
Joined: Mon Aug 04, 2014 8:26 am

CharacterController body speed, impulse and force

Post by nikolaiko » Tue Oct 28, 2014 9:07 am

Hi, I have a question about speed of the body under character controller and IsAffectedByGravity flag set to false.

I am using

Code: Select all

Controller.HorizontalMotionConstraint.MovementDirection = new Vector2(SpeedVector.X, SpeedVector.Z);
to set moving direction for character controller body. And it is ok, but I need to change speed of this body and apply some impulses at some moments. And this causes some problems for me. I trying to change AirSpeed parameter, it works. But look's like it have some limitation, because after value 100 or something near it velocity of the body didn't increse even if I set value to 10000.

And then I trying to Apply impulse using :

Code: Select all

Vector3 sp = new Vector3(0, 9000, 0);
cc.Body.ApplyLinearImpulse(ref sp);
loooks like nothing happend.

How I should change speed of body?

And how to apply impulse properly?

Maybe setting direction :

Code: Select all

Controller.HorizontalMotionConstraint.MovementDirection = new Vector2(SpeedVector.X, SpeedVector.Z);
is droping down impulse direction vectors?

Thanks.

Norbo
Site Admin
Posts: 4707
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController body speed, impulse and force

Post by Norbo » Tue Oct 28, 2014 8:51 pm

But look's like it have some limitation, because after value 100 or something near it velocity of the body didn't increse even if I set value to 10000. ... How I should change speed of body?
Changing the CharacterController's various speed related properties are indeed the way to change the speed of the character. The force related properties define how fast the character can reach those speeds.

Some ideas:
-Is there some external force stopping the character from accelerating?
-Is the CharacterController.AirForce set low enough that it doesn't look like it increases much, even though it is?
-Has the CharacterController.Body.LinearDamping been explicitly set to a high value (it defaults to 0)?
-Can you replicate the behavior in the BEPUphysicsDemos?
And then I trying to Apply impulse using :
Vector3 sp = new Vector3(0, 9000, 0);
cc.Body.ApplyLinearImpulse(ref sp);
loooks like nothing happend. ... how to apply impulse properly?
The most likely case is that the character fell asleep. ApplyLinearImpulse(ref Vector3) is a function designed for low overhead usage in constraints and similar use cases, so it does not do extra logic to wake the entity up.

Some options:
1) After using ApplyLinearImpulse, call Entity.ActivityInformation.Activate() to force the character active.
2) Use ApplyImpulse instead of ApplyLinearImpulse. ApplyImpulse calls Activate for you.
3) Set the LinearVelocity field directly to the desired speed rather than applying impulses. Setting LinearVelocity is equivalent to applying a linear impulse to reach the target velocity. Setting LinearVelocity calls Activate for you.

It may also be the VerticalMotionConstraint counteracting the impulse. This constraint is only active when the character has traction, though, and the default configuration is too weak to stop an impulse of 9000.
Maybe setting direction :
Code:
Controller.HorizontalMotionConstraint.MovementDirection = new Vector2(SpeedVector.X, SpeedVector.Z);

is droping down impulse direction vectors?
The horizontal motion constraint will fight against any motion not in the MovementDirection, if that is what you are wondering. It won't fight against an impulse along the characters up/down axis, though; it's strictly for horizontal motion.

nikolaiko
Posts: 43
Joined: Mon Aug 04, 2014 8:26 am

Re: CharacterController body speed, impulse and force

Post by nikolaiko » Thu Oct 30, 2014 12:21 pm

Ok, and how I can set vertical movement direction? I found VerticalMotionConstraint, but I can set direction there.
I want to create Homing missile, I found some scripts for it, but to implement it I need to set initial direction, speed and then in each frame just change forward direction (rotate) to direct missile to target.
I can change horizontal direction, but vertical don't know how.

Is there any way to do it?
Thanks.

Norbo
Site Admin
Posts: 4707
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController body speed, impulse and force

Post by Norbo » Thu Oct 30, 2014 9:44 pm

The CharacterController is designed for FPS-style character movement. It supports jumping, but there is nothing built in to help with arbitrary vertical motion.

A missile's behavior is very different from a character, so I would recommend not using the CharacterController at all. Instead, a simple entity could be used. Just change its angular velocity (or directly set the orientation if fine-grained collision response isn't important) and linear velocity as needed.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests