Hey everyone,
I'm working on a 3rd-person view type of game, and got a fair few things in place. One thing that I can't get in place is
collision. I've read the tutorials, and i'm using code which I know works, so I suspect my problem is something to do with:
a) Collision box for the model, currently I have none in place
or
b) Something's wrong with the model
or
c) My code is inefficient/isn't working properly.
Anyway, the problem is that whenever I collide with the object I specified collision for, the player object collides with thin air, much before it hits the actual object.
The code i'm using is this:
IF OBJECT COLLISION(10,13)>0
REPEAT
MOVE OBJECT 10,0-Speed#
POSITION CAMERA OBJECT POSITION X(10),50.0,OBJECT POSITION Z(10)-40
POINT CAMERA OBJECT POSITION X(10),3.0,OBJECT POSITION Z(10)
UNTIL OBJECT COLLISION(10,13)=0
ENDIF
I tested this code using simple cubes as object 10 and 13, and the collision worked perfectly, which makes me suspicious of it being a problem with the model(s) i'm using in the collision.
Here's a screenshot showing the problem in-game, where i'm using the .X models.
Here's the code, but using simple cubes, and it's compilable, so you can see the effect I want. It also proves that the problem isn't with my current code.
MAKE OBJECT CUBE 1,20
MAKE OBJECT CUBE 2,100
POSITION OBJECT 1,0,0,0
POSITION OBJECT 2,100,0,0
Speed#=0
DO
IF KEYSTATE(17)=1 THEN Speed#=1.4 : MOVE OBJECT 1,Speed#
IF KEYSTATE(30)=1 THEN Speed#=1.4 : TURN OBJECT LEFT 1,Speed#
IF KEYSTATE(32)=1 THEN Speed#=1.4 : TURN OBJECT RIGHT 1,Speed#
IF KEYSTATE(31)=1 THEN Speed#=0-1.4: MOVE OBJECT 1,Speed#
IF OBJECT COLLISION(1,2)>0
REPEAT
MOVE OBJECT 1,0-Speed#
POSITION CAMERA OBJECT POSITION X(1),50.0,OBJECT POSITION Z(1)-40
POINT CAMERA OBJECT POSITION X(1),3.0,OBJECT POSITION Z(1)
UNTIL OBJECT COLLISION(1,2)=0
ENDIF
LOOP
And a screen of the cube collision effect for those who can't/don't want to compile:
All help is appreciated, thanks in advance.