Jump to content

Controller


MrIslomaniac
 Share

Recommended Posts

I just made a new Player class for me but my controller now does not seem to work anymore, it just get stuck in the air where it is created(neither gravity nor collision).

I also tried the tutorial for controllers, but that does not work either ... any clues?

#include "engine.h"
int main(int argc, char** argv)
{
Initialize();
//Create a graphics context
Graphics(800,600);
//Create a world
if (!CreateWorld()) {
MessageBoxA(0,"Error","Failed to create world.",0);
goto exitapp;
}
//Create a camera
TEntity cam=CreateCamera();
CameraClearColor(cam,Vec4(0,0,1,1));
PositionEntity(cam,Vec3(0,2,-10));
Collisions(1,2,true);
//Load a model
TModel scene=LoadModel("scene.gmf");
if (scene==0) {
MessageBoxA(0,"Error","Failed to load model.",0);
goto exitapp;
}
EntityType(scene,2);
//Create a light
TLight light=CreatePointLight();
PositionEntity(light,Vec3(0,5,0));
//Create a render buffer
TBuffer buffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);
TController player=CreateController();
EntityType(player,1);
SetBodyDamping(player,0.0);
SetWorldGravity(Vec3(0,-20,0));
float move=0.0;
float strafe=0.0;
TVec3 camrotation=Vec3(0);
float mx=0;
float my=0;
HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
//Main loop
while(!KeyHit(KEY_ESCAPE)) {
//Camera looking
mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
camrotation.X=camrotation.X+my/10.0;
camrotation.Y=camrotation.Y-mx/10.0;
RotateEntity(cam,camrotation);
//Player movement
move=KeyDown(KEY_W)-KeyDown(KEY_S);
strafe=KeyDown(KEY_D)-KeyDown(KEY_A);
//Jumping
float jump=0.0;
if (KeyHit(KEY_SPACE)) {
if (!ControllerAirborne(player)) {
jump=4.0;
}
}
//Run
if (KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) {
if (!ControllerAirborne(player)) {
move*=2.0;
strafe*=2.0;
}
}
//Set controller input
UpdateController(player,camrotation.Y,move,strafe,jump);
//Update the world
UpdateWorld();
//Position the camera
TVec3 playerpos=EntityPosition(player);
TVec3 camerapos=EntityPosition(cam);
camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0);
camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z);
PositionEntity(cam,camerapos);
//Render the scene
SetBuffer(buffer);
RenderWorld();
//Render lighting
SetBuffer(BackBuffer());
RenderLights(buffer);
//Swap the front and back buffer
Flip();
}
exitapp:
return Terminate();
}

I think I am just missing something like SetCollision or SetMass ...

Greetz

Link to comment
Share on other sites

Have you set body mass for the controller?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Since that is the complete code, no :P

Ok that works now =) thank you!

Thought that i can't do that because it requires a TBody ...

Happy ;)

 

 

No problems, I never actually looked through your code as the problem is 99.9% of the time not giving the controller mass. ;)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

  • 3 weeks later...

add:

 

SetBodyMass(player,1);

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Change:

 

UpdateController(player,camrotation.Y,move,strafe,jump);

 

try:

 

UpdateController(player,camrotation.Y,move*3,strafe*3,jump,500.0f);

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

post your code.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

#include "engine.h"

int main(int argc, char** argv)

{

Initialize();

//Create a graphics context

Graphics(1280,768);

//Create a world

if (!CreateWorld()) {

MessageBoxA(0,"Error","Failed to create world.",0);

goto exitapp;

}

//Create a camera

TEntity cam=CreateCamera();

CameraClearColor(cam,Vec4(0,0,1,1));

PositionEntity(cam,Vec3(0,2,-10));

Collisions(1,2,true);

//Load a model

TModel scene=LoadModel("c://scene.gmf");

if (scene==0) {

MessageBoxA(0,"Error","Failed to load model.",0);

goto exitapp;

}

EntityType(scene,2);

//Create a light

TLight light=CreatePointLight();

PositionEntity(light,Vec3(0,5,0));

//Create a render buffer

TBuffer buffer=CreateBuffer(1280,768,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

TController player=CreateController();

EntityType(player,1);

SetBodyMass(player,1);

SetBodyDamping(player,0.0);

SetWorldGravity(Vec3(0,-20,0));

float move=0.0;

float strafe=0.0;

TVec3 camrotation=Vec3(0);

float mx=0;

float my=0;

HideMouse();

MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

//Main loop

while(!KeyHit(KEY_ESCAPE)) {

//Camera looking

mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);

my=Curve(MouseY()-GraphicsHeight()/2,my,6);

MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

camrotation.X=camrotation.X+my/10.0;

camrotation.Y=camrotation.Y-mx/10.0;

RotateEntity(cam,camrotation);

//Player movement

move=KeyDown(KEY_W)-KeyDown(KEY_S);

strafe=KeyDown(KEY_D)-KeyDown(KEY_A);

//Jumping

float jump=0.0;

if (KeyHit(KEY_SPACE)) {

if (!ControllerAirborne(player)) {

jump=4.0;

}

}

//Run

if (KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) {

if (!ControllerAirborne(player)) {

move*=2.0;

strafe*=2.0;

}

}

//Set controller input

UpdateController(player,camrotation.Y,move*3,strafe*3,jump,500.0f);

//Update the world

UpdateWorld();

//Position the camera

TVec3 playerpos=EntityPosition(player);

TVec3 camerapos=EntityPosition(cam);

camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0);

camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z);

PositionEntity(cam,camerapos);

//Render the scene

SetBuffer(buffer);

RenderWorld();

//Render lighting

SetBuffer(BackBuffer());

RenderLights(buffer);

//Swap the front and back buffer

Flip();

}

exitapp:

return Terminate();

}

Link to comment
Share on other sites

when you say moves off screen do you mean fall ?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

looks like you are loading a gmf and not a sbx file for your scene... you need to create a sbx file in the editor and load that using LoadScene() not LoadModel()... your player doesn't have anything to spawn on perhaps? unless maybe your scene.gmf is an actual scene?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

This code works:

 

 

#include "engine.h" 



int main(int argc, char** argv) 
{ 

Initialize(); 

//Create a graphics context 

Graphics(1280,768); 

//Create a world 

if (!CreateWorld()) { 
MessageBoxA(0,"Error","Failed to create world.",0); 
goto exitapp; 
} 


//Create a camera 
TEntity cam=CreateCamera(); 
CameraClearColor(cam,Vec4(0,0,1,1)); 
PositionEntity(cam,Vec3(0,2,-10)); 
Collisions(1,2,true); 

//Load a model 
TModel scene=LoadModel("abstract::scene.gmf"); 
if (scene==0) { 
MessageBoxA(0,"Error","Failed to load model.",0); 
goto exitapp; 
} 

EntityType(scene,2); 
//Create a light 

TLight light=CreatePointLight(); 
PositionEntity(light,Vec3(0,5,0)); 

//Create a render buffer 
TBuffer buffer=CreateBuffer(1280,768,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); 

TController player=CreateController(); 
EntityType(player,1); 
SetBodyDamping(player,0.0); 
SetBodyMass(player,1);
SetWorldGravity(Vec3(0,-20,0)); 


float move=0.0; 
float strafe=0.0; 
TVec3 camrotation=Vec3(0); 
float mx=0; 
float my=0; 

HideMouse(); 
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2); 

//Main loop 
while(!KeyHit(KEY_ESCAPE)) { 

//Camera looking 
mx=Curve(MouseX()-GraphicsWidth()/2,mx,6); 
my=Curve(MouseY()-GraphicsHeight()/2,my,6); 
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2); 
camrotation.X=camrotation.X+my/10.0; 
camrotation.Y=camrotation.Y-mx/10.0; 
RotateEntity(cam,camrotation); 

//Player movement 
move=KeyDown(KEY_W)-KeyDown(KEY_S); 
strafe=KeyDown(KEY_D)-KeyDown(KEY_A); 

//Jumping 
float jump=0.0; 
if (KeyHit(KEY_SPACE)) { 
if (!ControllerAirborne(player)) { 
jump=4.0; 
} 
} 

//Run 
if (KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) { 
if (!ControllerAirborne(player)) { 
move*=2.0; 
strafe*=2.0; 
} 
} 

//Set controller input 
UpdateController(player,camrotation.Y,move*3,strafe*3,jump,500.0f); 

//Update the world 
UpdateWorld(); 

//Position the camera 
TVec3 playerpos=EntityPosition(player); 
TVec3 camerapos=EntityPosition(cam); 
camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0); 
camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z); 
PositionEntity(cam,camerapos); 

//Render the scene 
SetBuffer(buffer); 
RenderWorld(); 

//Render lighting 
SetBuffer(BackBuffer()); 
RenderLights(buffer); 

//Swap the front and back buffer 
Flip(); 
} 

exitapp: 
return Terminate(); 
}

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

yes

 

 

Is this still a problem?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Have you tried moving the start position of the player controller up? are you still using the same .gmf scene?

 

try:

 

PostionEntity(player, Vec3(0.0, 5.0, 0.0));

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

regulate?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

if you mean the starting height value for the position of the controler then you use PostionEntity as above the Vec3 is three values for that postion Vec3(x,y,z) ... the value for y (5.0 as above) sets the height.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...