Character Controller

General discussion around Urho3D.

Re: Character Controller

PostPosted by bvanevery » 21 Dec 2015, 21:43

JamesK89 wrote:The purposed character hull looks like a Bacteriophage virus to me.


I've considered making more abstract geometric games of entities that are actually such, although I think of pawns in chess, not viruses. Hey if Minecraft can be ugly and eventually sell to MS for billions, why do we have to make nice human appearances and canned animations?
User avatar
bvanevery
Some active
Some active
 
Posts: 50
Joined: 16 Aug 2015, 05:59

Re: Character Controller

PostPosted by JamesK89 » 28 Dec 2015, 20:05

I found this article if anyone wants to look at it: http://codefreax.org/tutorials/view/id/3
From what I can tell from a preliminary standpoint is that it seems to manually control player movement using a ghost convex shape and performs convex sweep tests against Bullet's collision world.

It's written in Ogre and Bullet but should be adaptable to Urho3D especially given that the same physics engine is used.


On the other hand last evening I was looking at some of the assets from Frictional Games' SOMA in Blender and noticed that objects like stairs have an invisible collision ramp enveloping the stairs and after taking a look at the source code for Penumbra and HPL1 Engine I'm thinking maybe dynamic character controllers are not as bad as they used to be.
User avatar
JamesK89
New user
New user
 
Posts: 15
Joined: 03 Feb 2015, 05:50
Location: North Carolina, USA

Re: Character Controller

PostPosted by Enhex » 28 Dec 2015, 20:57

I implemented convex cast suspension based dynamic controller and it works fine. Though it complicates interactions since the rigidbody doesn't span all the way to the ground so another body is required, and a way to attach it to the controller body without parenting it if u want to detect collision with inactive objects like pickups (fixed constraint may work for it).
User avatar
Enhex
Most active user
Most active user
 
Posts: 325
Joined: 31 Dec 2014, 12:23

Re: Character Controller

PostPosted by thebluefish » 29 Dec 2015, 05:45

It should be easy to make a small component which takes the world transformation for one node and set it to the node that the component is attached to. Then all you need to do is plug a node id in, possibly as an attribute that can be set in the editor, and voila.
something something signature here

Code: Select all
DVIS_> i just formatted the only copy of my pgp master and recovery keys
User avatar
thebluefish
Most active user
Most active user
 
Posts: 367
Joined: 14 Apr 2014, 03:25
Location: United States

Re: Character Controller

PostPosted by Zaroio » 28 Jun 2016, 15:18

Enhex wrote:I implemented convex cast suspension based dynamic controller and it works fine. Though it complicates interactions since the rigidbody doesn't span all the way to the ground so another body is required, and a way to attach it to the controller body without parenting it if u want to detect collision with inactive objects like pickups (fixed constraint may work for it).



Sorrey for reviving this again...

I've lost my whole hd... realy want to kill myself know :lol:

Code: Select all
    btCapsuleShape foot(0.4f, 0.5f);

    PhysicsRaycastResult ray;

    //world->SphereCast(ray, Ray(node_->GetPosition(), Vector3::DOWN), 0.4, 1.0f);

     world->ConvexCast(ray, &foot, node_->GetPosition(), Quaternion::IDENTITY,
                       node_->GetPosition() + Vector3(0, -1.0f, 0), Quaternion::IDENTITY);

    if (ray.body_ && ray.body_ != m_body) {
        Vector3 newPos = node_->GetPosition();
        newPos.y_ = ray.position_.y_ + 1.0f;
        node_->SetPosition(newPos);
        std::cout << ray.distance_ << std::endl;
        ray.body_->SetMass(0);
    }


After losing my other engine project, I’ve desired to move to Urho3D again. I’ve done the casting and everything seems to work all right. Except that it does some annoying jitter when getting slowly out of an edge. Am i setting it’s position on the right time?
User avatar
Zaroio
New user
New user
 
Posts: 5
Joined: 12 Oct 2014, 16:10

Re: Character Controller

PostPosted by TheComet » 03 Jul 2016, 22:05

I thought I'd dump my camera controller implementation here for people to look at. I've found that managing your own velocities and applying them with body->SetLinearVelocity() gives you a lot more freedom in how you want to control your character, without having to screw around with the physics engine too much. One thing I'll most likely add is collision feedback from bullet. Currently, the velocity is applied regardless of what you're colliding with, so when interacting with other collision objects you just tear through them with constant force. This makes it impossible to jump on top of other collision objects, for example.

My implementation feels almost identical to Half Life 2 (which is what I was inspired by). When you jump your velocity increases, and I've deliberately made it possible for you to chain jumps to gain more speed (known as "Bunny Hopping").

Sources can be found here:
CameraController.h
CameraController.cpp

It's still a work in progress, as you can see with all of the TODOs in the code. You can switch between freecam mode and FPS mode by calling CameraController::SetMode().

Video:


This is the relevant section of code:
Code: Select all
void CameraController::UpdateFPSCameraMovement(float timeStep)
{
    RigidBody* body = moveNode_->GetComponent<RigidBody>();

    // Get input direction vector
    float speed = 8.0f; // TODO read this from an XML config file
    Vector3 targetPlaneVelocity(Vector2::ZERO);
    if(input_->GetKeyDown(KEY_W))     targetPlaneVelocity.z_ += 1;
    if(input_->GetKeyDown(KEY_S))     targetPlaneVelocity.z_ -= 1;
    if(input_->GetKeyDown(KEY_A))     targetPlaneVelocity.x_ += 1;
    if(input_->GetKeyDown(KEY_D))     targetPlaneVelocity.x_ -= 1;
    if(targetPlaneVelocity.x_ != 0 || targetPlaneVelocity.z_ != 0)
        targetPlaneVelocity = targetPlaneVelocity.Normalized() * speed;

    // Rotate input direction by camera angle using a 3D rotation matrix
    targetPlaneVelocity = Matrix3(-Cos(angleY_), 0, Sin(angleY_),
                              0, 1, 0,
                              Sin(angleY_), 0, Cos(angleY_)) * targetPlaneVelocity;

    // Controls the player's Y velocity. The velocity is reset to 0.0f when
    // E_NODECOLLISION occurs and the player is on the ground. Allow the player
    // to jump by pressing space while the velocity is 0.0f.
    if(input_->GetKeyDown(KEY_SPACE) && downVelocity_ == 0.0f)
    {
        downVelocity_ = playerParameters_.jumpForce;
        // Give the player a slight speed boost so he moves faster than usual
        // in the air.
        planeVelocity_ *= playerParameters_.jumpSpeedBoostFactor;
    }

    // TODO limit velocity on slopes?

    // TODO Take upwards velocity into account when bunny hopping (e.g. on ramps)

    // smoothly approach target direction if we're on the ground. Otherwise
    // just maintain whatever plane velocity we had previously.
    float smoothness = 16.0f;
    if(downVelocity_ == 0.0f)
        planeVelocity_ += (targetPlaneVelocity - planeVelocity_) * timeStep * smoothness;

    // Integrate gravity to get Y velocity
    downVelocity_ += physicsWorld_->GetGravity().y_ * timeStep;

    // update camera position
    Vector3 velocity(planeVelocity_.x_, downVelocity_, planeVelocity_.z_);
    body->SetLinearVelocity(velocity);
}

// ----------------------------------------------------------------------------
void CameraController::HandleNodeCollision(StringHash eventType, VariantMap& eventData)
{
    using namespace NodeCollision;
    (void)eventType;
    (void)eventData;

    RigidBody* body = moveNode_->GetComponent<RigidBody>();

    // Temporarily disable collision checks for the player's rigid body, so
    // raycasts don't collide with ourselves.
    unsigned int storeCollisionMask = body->GetCollisionMask();
    body->SetCollisionMask(0);

        // Cast a ray down and check if we're on the ground
        PhysicsRaycastResult result;
        float rayCastLength = playerParameters_.height * 1.05;
        Ray ray(moveNode_->GetWorldPosition(), Vector3::DOWN);
        physicsWorld_->RaycastSingle(result, ray, rayCastLength);
        if(result.distance_ < rayCastLength)
            // Reset player's Y velocity
            downVelocity_ = 0.0f;

    // Restore collision mask
    body->SetCollisionMask(storeCollisionMask);
}
I'm a non-binary non-cis sexually fluid cephalopod identifying genderqueer mocha frappé latte
User avatar
TheComet
Active user
Active user
 
Posts: 122
Joined: 29 Jan 2014, 14:07
Location: Germany

Re: Character Controller

PostPosted by Zaroio » 04 Jul 2016, 00:36

Thank you very very much my friend. :D
User avatar
Zaroio
New user
New user
 
Posts: 5
Joined: 12 Oct 2014, 16:10

Re: Character Controller

PostPosted by hd_ » 05 Jul 2016, 01:19

In my fps controller experiment, I stuck with the bullet forces method to avoid the extra work of collision detection/response. I started with the character sample and made use of several collision triggers to control different behaviors (like ground detect, drop detect, stand detect), and added some fudge. I added a half-life style crouch-jump (or at least how I remember it). In most cases it behaves well as I've limited extreme responses, but there are some glitches like wall climbing and it doesn't handle stairs well (although ramps are good).

I used a simple trick to smooth out the collisions by separating the character controller physics from the visual model, that way even if there are hiccups, the visual model is always moving fluidly. If you wanted to then do hitboxes, or IK steps, you would do it based on the visual model position rather than the character controller.

Source: https://github.com/hdunderscore/Urho3D-FPS-Controller
User avatar
hd_
Contributor
Contributor
 
Posts: 220
Joined: 21 Jul 2014, 08:55
Location: Australia

Re: Character Controller

PostPosted by Lumak » 19 Dec 2016, 09:45

I don't play FPS games but always wondered why capsule shape rigid body can't be used.
I tested this to see if can be done, and below is the video.

https://youtu.be/OSRAUEXIKBI

Lumak
Have many posts
Have many posts
 
Posts: 425
Joined: 08 Jun 2015, 15:38

Re: Character Controller

PostPosted by Eugene » 19 Dec 2016, 11:42

I know one annoying problem of true-RB character controller that I've seen on Bullet few years ago: nobody promises that rigid body will move with speed that you set.
E.g. try to move RB rapidly over heightmap/trimesh geometry. You may notice that character sometimes don't move smoothly with expected speed because of inaccuracy of physics computation and colliding with ground.
User avatar
Eugene
Some active
Some active
 
Posts: 62
Joined: 06 Jun 2016, 06:30
Location: Russia

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron