This is brilliant Vermeer
Just wish I could get my collision to work and then I can move on with my project!
This is brilliant Vermeer
Just wish I could get my collision to work and then I can move on with my project!
Wish I was as far along as you! My stupid textures refuse to work… I also need to offset my chunks but that isnt working… sigh
Is collision really that hard? Isn’t it just AABBs colliding with a sphere?
Hi,
Collision should be simple, but my issue I think is not getting the correct camera position vector, when turning 180 degs.
Thanks
How about: Make it impossible that the rotation is bigger than 180 degrees?
It’s easy!
while(rotation_y > 180)
rotation_y -= 180;
Oh, and please use AABB’s for collision detection.
It’s the most easy collision detection one can think of.
Update:
Testing flowing water
UlUXzt5EfdY
Hi,
I want to allow the camera to turn 360 degs
Camera position is fine, I think it is my scaling, please look at this video I have done, we can see that the block I’m on isn’t accurate with block I’m trying to jump on, it is as though the block is more than one unit wide…again, this a scaling issue?
video:
https://www.youtube.com/watch?v=OVJrbdVt-b0
When on block 8,0,1 then this is the block we can jump on, but when moving, we can see that we should still be able to jump on block when on block 8,0,2 - it just doesn’t seem accurate. Also, when I do get on top of the box and then fall off it, it looks wrong. Can’t fabben it out, should be simple.
int blockX = (int) Math.abs(Math.floor(pos.x));
int blockZ = (int) Math.abs(Math.floor(pos.z));
int blockY = (int) Math.abs(Math.floor(pos.y));
Above gets position and then I just do this to get the block and check if it is active:
Block b = ChunkManager.getInstance().getBlockInChunk(chunktoget, blockX,blockY,blockZ);
if(!b.isActive() ) { // do whatever -> move camera down }
This is why I think it is to do with scaling.
I set view matrix up at start:
GL11.glTranslatef(-0.5f, -2f, -1f);
gluLookAt(0, 0, -1,
0, 0, 0,
0, 1, 0);
Anything obviously wrong?!
Thanks again and sorry for keep going on about this!
That is looking awesome! 8)
Gee whiz! Your game is really starting to look cool
Hi,
How do you keep the block selection on screen i.e. so it doesn’t go behind the floor etc when looking down?
I tried glDisable(GL_DEPTH_TEST); but my block appears then inside out so to speak…
Hope you know what I mean?!
Thanks
Thank you all for oyur positive comments
Steg,
You mean the block the player is holding?
// draw the block the player is holding
GL11.glLoadIdentity();
//move the camera
GL11.glRotatef(20, 1.0f, 0, 0); //lookupdown
GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0); //360.0f - yrot
GL11.glTranslatef(-xpos, (-walkbias/3) - 0.25f - (float)playerheight - hedHeight, -zpos);
//move the block infront of the player
float xblokpos = xpos - (float) Math.sin((yrot-18) * piover180) * 0.24f;
float zblokpos = zpos - (float) Math.cos((yrot-18) * piover180) * 0.24f;
GL11.glTranslatef(xblokpos, playerheight+1.83f, zblokpos);
GL11.glRotatef(340.0f + yrot, 0,1f, 0f);
its rotated to the side of the player by 18, and tilted down by 20 (GL11.glRotatef(20, 1.0f, 0, 0); )
Once the camera is rotated, I place the block infront of the player with xblokpos zblockpos (the block is 0.24 units from the player camera)
The block is then rotated to maintain its relative rotation to the player
I have also reduced the effect of the walkbias by /3 to minimise, but not remove the bobbing effect on the block, as its close to the camera.
Hope this is of some help. The values you want to use may be trial and error! To get the look you want to have.
@Steg
When initialy testing, my movement and block detection, I made the block im standing on change colour, also I had textures with a grid pattern, and drew wireframe boxes to make tests and be sure exactly what was heappening.
Another very good way is to output your character position information, and the position when there has been a collision, and see if they are as expected.
Aslo I dont know if you have negative positions in your map, but depending on how you are working out the block, it may not work as expected when going negative.
This may not be a standard soloution, and im not sugesting you do this, but the solution works in my game.
int x;
if(xp>=0){
x=(int)(xp+0.5);
} else {
x=(int)(xp-0.5);
}
I always at 0.5 to the block to get to the block middle, x is a float of a position so say 29.6 … this would mean i check block 30!
Aslo I dont use abs or floor, but I use modulo to get the position in the chunk so 30%16 = 14 so its block 14 in x on that chunk.
Again I may not be using best practice, but this works fine for me. Other people may be able to sugest alternatives, that work better for your game.
And again: How about using AABB?
Here’s the Method i use, in Pseudocode.
I learned it from Minecraft’s Code a long time ago (After the first Halloween Update),
and now i use it really everywhere.
The best thing about this method is, that it is totally failsafe!
The worst thing that can happen, is when your velocity is insanely high, that you go trough blocks.
Just make sure your velocity is never bigger than your updaterate in milliseconds.
Pseudocode:
List<AABB> boxes = world.getCollisionBoxesInRange(player.x,player.y,player.z,player.squaredSize);
double cvelocity_x = player.velocity_x;
double cvelocity_y = player.velocity_y;
double cvelocity_z = player.velocity_z;
// X Axis Check
for(AABB box : boxes){
cvelocity_x = box.getIntersectionOffsetX(player,cvelocity_x);
}
// Z Axis Check
for(AABB box : boxes){
cvelocity_z = box.getIntersectionOffsetZ(player,cvelocity_z);
}
// Y Axis Check
for(AABB box : boxes){
cvelocity_y = box.getIntersectionOffsetY(player,cvelocity_y);
}
if(player.velocity_x != cvelocity_x)
cvelocity_x = 0;
if(player.velocity_z != cvelocity_z)
cvelocity_z = 0;
if(player.velocity_y != cvelocity_y)
{
cvelocity_y = 0;
}
player.velocity_x = cvelocity_x;
player.velocity_y = cvelocity_y;
player.velocity_z = cvelocity_z;
player.x += player.velocity_x;
player.y += player.velocity_y;
player.z += player.velocity_z;
player.doRecalculateEntityBoundingBox();
=====================================
public double getIntersectionOffsetY(AABB boxToTestAgainst, double velocity)
{
if (boxToTestAgainst.x1 <= x0 || boxToTestAgainst.x0 >= x1)
{
return velocity;
}
if (boxToTestAgainst.z1 <= z0 || boxToTestAgainst.z0 >= z1)
{
return velocity;
}
if (par2 > 0.0D && boxToTestAgainst.y1 <= y0)
{
double d = y0 - boxToTestAgainst.y1;
if (d < velocity)
{
velocity= d;
}
}
if (par2 < 0.0D && boxToTestAgainst.y0 >= y1)
{
double d1 = y1 - boxToTestAgainst.y0;
if (d1 > velocity)
{
velocity = d1;
}
}
return velocity;
}
The best thing you can do is to take a look at Minecraft’s Collision Code (use MCP to get the code),
and then figure out how it works.
And don’t just copy it, because that doesn’t help you at all and won’t work out very well.
I copyed it too at first, and it didn’t work, so i learned hwo it work’s and made my own that works with my engine.
PS: Any fails/errors/mistakes in this post are there because of the extreme headache i have right now.
Hi, thank you for taking the time to post all that. I’ll give that a try and let you know how it goes. Though my collision does work, I am after all doing the project to learn new stuff and expand techniques.
Yes, I have already had to be mindful of high a velocity with my code.
I’ll also take a peek at minecraft code for this. Thanks again for taking the time to help.
@steg. It’s no bad thing to try and get it to work your way, then update it when your ready. I stand by my method, but Longor make a convincing case to look at AABB.
Time to make a some tools:
Note for the trianglar face I will probably change it to a quad (thats almost a point). Odd how you notice mistakes just as you posting something!
Ill hard code models for now, then switch to a model loader - as described by the Coding Universe if I want more complex models.
Hey thanks for all the information guys
The AABB looks great, will google the MCP stuff and look.
I guess it be a good idea to change the block colours that are around the player?
My player is basically the camera’s position, is this correct?
I already output player position, block we are on etc, block on is correct and where collision should occur but it isn’t very accurate, may need something like you have done with the offset of 0.5 or something?
I don’t understand though how you would use this:
int x;
if(xp>=0){
x=(int)(xp+0.5);
} else {
x=(int)(xp-0.5);
}
What is xp?
Yes, the block the player is holding, I just do this:
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glLoadIdentity();
glTranslatef(-1,0,4f);
glRotatef(20,0,0,1);
But cube now inside out but doesn’t go through the floor…I guess this is wrong?
What do you set your playerheight too and do you need to take this into account when doing your collision check?
Thanks again, really appreciate all this!
That tool looks awesome ;D
@steg
The xp is player x. So I use it in my function to get the current block. I put it on to show that if the player position is negative I subtract 0.5. That’s all it does.
No, don’t disable depth test, that will make a mess (only do that for 2d)
My player is the camera yea. The camera is 1.8 high above the players feet(floor)
ok, did use the depth test for my skybox…although got the skybox turned off at the moment.
Without depth test disabled, this video shows what happens:
https://www.youtube.com/watch?v=lPdD6eNzTlQ
Guess I’ve not got the camera set at the correct height or something?
Do you use gluLookat? I’ve got this at the start:
gluPerspective(
45.0f,
(float) Display.getWidth() / (float) Display.getHeight(),
0.1f,
100.0f);
GL11.glTranslatef(0, -2f, 2f);
gluLookAt(0, 0, -2,
0, 0, 0,
0, 1, 0);
glMatrixMode(GL_MODELVIEW);
Just doesn’t seem to look right?..
I forgot to mention something steg,
The box the player is holding is a small block, I forget how big exactly, but much smaller than a game cube, it may be like 0.1 big
It just looks big as its near the camera, this means it won’t touch the floor!