Jump to content

BGerman

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by BGerman

  1. Fellow developers, I have made this LEO example to illustrate what is wrong:

    // ====================================================================
    // This file was generated by LEBuilder
    // http://leadwerks.com/werkspace
    // ====================================================================
    #include "leo.h"
    #include <string>
    #include <iostream>
    using namespace std;
    using namespace LEO;
    const int ScreenWidth = 800;
    const int ScreenHeight = 600;
    const char* MediaDir = "C:/Leadwerks Engine SDK";
    const char* AppTitle = "Character controller bug?";
    const int Group_Normal = 1;
    const int Group_Mover = 2;
    const int Group_Player = 3;
    void ErrOut( const string& message ) { cerr << message << endl; }
    // --------------------------------------------
    int main( int argc, char* argv[] )
    {
    // Set graphics mode
    Engine engine(AppTitle,ScreenWidth,ScreenHeight);
    if( !engine.IsValid() )
    {
    ErrOut( "Failed to set graphics mode.");
    return 1;
    }
    engine.AddAbstractPath( MediaDir );
    // Create framework object and set it to a global object so other scripts can access it
    Framework fw;
    if( NULL == fw )
    {
    ErrOut( "Failed to initialize engine." );
    return 1;
    }
    // Set Lua framework object
    engine.SetObject( "fw", fw );
    
    // Set Lua framework variable
    Lua lua;
    lua.PushObject( fw );
    lua.SetGlobal( "fw" );
    lua.Pop( 1 );
    // Get framework main camera
    fw.main.GetCamera().SetPosition( Vec3(0,20,-20));
    fw.main.GetCamera().SetRotation( Vec3(45,0,0));
    // Create cube
    TBody cubeBody=CreateBodyBox(2,2,2);
    PositionEntity(cubeBody,Vec3(-3,5,-3));
    // Create ground
    TBody groundBody=CreateBodyBox(20,2,20);
    PositionEntity(groundBody,Vec3(0,-3,0));
    //Create elevator
    TBody elevatorBody=CreateBodyBox(8,2,8);
    PositionEntity(elevatorBody,Vec3(0,0,0));
    SetBodyGravityMode(elevatorBody,false);
    //Create player
    TController playerController=CreateController(7.5,1.5,0.5,45,5);
    PositionEntity(playerController,Vec3(3,5,3),1);
    //Assign types
    EntityType(cubeBody,Group_Normal);
    EntityType(groundBody,Group_Normal);
    EntityType(elevatorBody,Group_Mover);
    EntityType(playerController,Group_Player);
    //Assign mass
    SetBodyMass(groundBody,0);
    SetBodyMass(cubeBody,1);
    SetBodyMass(elevatorBody,1000);
    SetBodyMass(playerController,5);
    //Set collisions
    SetWorldGravity(Vec3(0,-15,0));
    Collisions::Set(Group_Normal,Group_Normal,SLIDINGCOLLISION);
    Collisions::Set(Group_Normal,Group_Mover,SLIDINGCOLLISION);
    Collisions::Set(Group_Normal,Group_Player,SLIDINGCOLLISION);
    Collisions::Set(Group_Mover,Group_Mover,SLIDINGCOLLISION);
    Collisions::Set(Group_Mover,Group_Player,SLIDINGCOLLISION);
    Collisions::Set(Group_Player,Group_Player,SLIDINGCOLLISION);
    DebugPhysics();
    // Spin cube until user hits Escape
    while( !Keyboard::I****() && !engine.IsTerminated() )
    {
    if( !engine.IsSuspended() )
    {
    UpdateWorld();
    //Update character controller
    float move=(KeyDown(KEY_W)-KeyDown(KEY_S))*10;
    float strafe=(KeyDown(KEY_D)-KeyDown(KEY_A))*10;
    float jump=0.0;
    if (KeyHit(KEY_LSHIFT)) {
    if (!ControllerAirborne(playerController)) {
     jump=15.0;
    }
    }
    UpdateController(playerController,0.0,move,strafe,jump,20);
    //Add mover velocity
    if(KeyDown(KEY_LCONTROL)){
    AddBodyForce(elevatorBody,Vec3(0,4000,0),1);
    }
    if(KeyDown(KEY_SPACE)){
    AddBodyForce(elevatorBody,Vec3(0,-4000,0),1);
    }
    if(KeyDown(KEY_RIGHT)){
    AddBodyForce(elevatorBody,Vec3(4000,0,0),1);
    }
    if(KeyDown(KEY_LEFT)){
    AddBodyForce(elevatorBody,Vec3(-4000,0,0),1);
    }
    if(KeyDown(KEY_UP)){
    AddBodyForce(elevatorBody,Vec3(0,0,4000),1);
    }
    if(KeyDown(KEY_DOWN)){
    AddBodyForce(elevatorBody,Vec3(0,0,-4000),1);
    }
    //This fixes the controller
    if(KeyDown(KEY_X)){
    RotateEntity(playerController,Vec3(0.5,0,0),1);
    }
    SetBodyTorque(elevatorBody,Vec3(0,0,0),1);
    RotateEntity(elevatorBody,Vec3(0,0,0),1);
    fw.Update();
    fw.Render();
    DrawText(20,20,"Use Arrow keys to move platform around, use Ctrl and Space to move up and down");
    DrawText(20,40,"Use W,A,S,D to move character controller around. Use LShift to jump");
    DrawText(20,60,"Character controller does not move along, press X to apply solution");
    engine.Flip(1);
    }
    }
    
    return engine.Free();
    }
    

     

    Run it and see it yourselves. The character controller does not move accordingly unless it is rotated slightly. dont know if there is another way but that works, for now...

     

    Video of this program in action, I press X on second 60, and you can see it now behaves the way it should. All pressing x does is:

    //This fixes the controller
    if(KeyDown(KEY_X)){
    RotateEntity(playerController,Vec3(0.5,0,0),1);
    }
    

     

     

    Can this be considered a real bug?

    • Upvote 1
  2. Yes, that is the solution, but i was getting some weird bugs. This is the way I am doing it right now and it works... Kinda...

     

    I added the callback function:

    int _stdcall moverCollision( TEntity entity0, TEntity entity1, byte* position, byte* normal, byte* force, flt speed )
    {
    flag = GetEntityType(entity1);
    PositionEntity(entity1,
     (EntityPosition(entity1,1)-EntityPosition(entity0,1))+
     EntityPosition(entity0,1),1);
    
       return 0;
    }
    

     

    And it works Great with normal bodies. But it does not work with character controllers unless you rotate it on X or Z axis by at least one degree....

  3. Guys guys, you are explaining it right and i know what you mean, something like a seat in a vehicle a static object linked to other, that is not what i mean or want, Here is a video that ilustrates what i am trying to acomplish:

     

     

    One player gets IN the vehicle to pilot it, (No character controller as you all are saying, static, inside the vehicle) BUT, the other player gets ON the vehicle (On top, not on a seat, and can move freely on top of it dynamically and can simply walk or jump off, nothing scripted, but the vehicle still moves him). THAT is what i want to achieve.

     

    As an experiment, open up the editor, spawn a viperscout vehicle with physics paused, press the "switch to game" button while on top of it, and if the vehicle starts moving, you will stay in the same spot as the vehicle slides below you. this is the default behavior and is not what i want.

     

    Here is my progress so far:

    http://www.youtube.com/watch?v=5mmUf2fwsEs
    

     

    As you can see, the character controller just slides, but the box does move around with the platform. And this does not happen with default settings! go ahead and try it and see what i am talking about.

  4. I've gotten to a point where i need vehicle-like entities, such as an elevator or a boat. I've had no problem implementing an elevator, but i do have a problem with boat and car-like entities.

     

    The problem is, when an entity moves on either X or Z axis (sides), any object on top, or any character controller, does not move along with it, it stays in the same position it was before.

     

    I know it can be done with a collision callback function and i do know how it is done, but, is there any easy, fast way to achieve this effect?

     

    Edit:

     

    Ok, so i went ahead and did it the callback way, added a callback function:

    int _stdcall moverCollision( TEntity entity0, TEntity entity1, byte* position, byte* normal, byte* force, flt speed )
    {
    AddBodyForce(entity1,GetBodyVelocity(entity0,1));
    return 0;
    }
    

     

    and set the callback function:

    SetEntityCallback(elevatorBody,(BP)moverCollision,ENTITYCALLBACK_COLLISION);
    
    

     

    And it works GREAT with normal bodies, but not with character controllers... any suggestion? I already tried with UpdateController to no avail.

     

    Will i have to create my own character controller?

  5. Great! Thank you so much for pointing me in the right direction Josh. For anyone who is interested, i managed to get the results i wanted.

     

    Since i use the "mesh.vert" shader on most of the objects, i went to experiment with it. I first renamed shaders.pak to shaders.zip to access the shaders. I added scale and offset uniform variables:

    uniform vec2 texscale = vec2(1.0,1.0);;
    uniform vec2 texoffset;
    

     

    and modified two lines of code to add, and multiply the texcoords:

    texcoord0=gl_MultiTexCoord0.xy*texscale+texoffset;
    texcoord1=gl_MultiTexCoord1.xy*texscale+texoffset;
    

     

    To access, scale and offset textures i use:

    SetShaderVec2(shader,"texscale",Vec2(scaleU,scaleV));
    SetShaderVec2(shader,"texoffset",Vec2(scrollU,scrollV));
    

     

     

    And it works great. Any suggestions or questions are welcome.

     

    Note that this will affect the material you grabbed the shader of, using:

    TShader shader=GetMaterialShader(yourMaterial);
    

    • Upvote 3
×
×
  • Create New...