Hi
In some games, we can have a physic box for the main character and for the others characters.
So, when we meet the others characters (ennemies for examples), we can push them (we don't go through them).
I have tried to do this in AGk. I would like to use the kinematic body, but they only interact with dynamicbody.
Do I don't know How I can do that.
Here is my test, but id doesn't work as wanted :
// Project: Characters physic
// Created: 2015-11-18
// set window properties
SetWindowTitle( "3D_alphabug" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Create3DPhysicsWorld()
Set3DPhysicsGravity(0,-10,0)
//LoadObject(100,"tree.obj")
//LoadImage(1,"tree.png")
//the ground
CreateObjectPlane(4,50,50)
SetObjectRotation(4,90,0,0)
Create3DPhysicsStaticBody(4)
SetObjectShapeBox(4)
SetObject3DPhysicsDamping(4,0,0)
SetObject3DPhysicsFriction(4,200)
m = 100 // mass
f = 5 // friction
// the player : a red box
n = 1
CreateObjectBox(n,2,2,2)
SetObjectPosition(n,0,10,0)
SetObjectColor(n,255,0,0,255)
Create3DPhysicsKinematicBody(n)
SetObjectShapeBox(n)
SetObject3DPhysicsDamping(n,0,0)
SetObject3DPhysicsMass(n,m)
// the mouse-box
n=2
CreateObjectBox(n,2,2,2)
SetObjectPosition(n,2,20,0)
SetObjectColor(n,0,100,255,255)
/*
Create3DPhysicsKinematicBody(n)
SetObjectShapeBox(n)
SetObject3DPhysicsDamping(n,0,0)
SetObject3DPhysicsMass(n,m)
*/
//the box static
n=3
CreateObjectBox(n,2,2,2)
SetObjectPosition(n,-5,1,0)
SetObjectColor(n,0,120,120,255)
Create3DPhysicsStaticBody(n)
SetObjectShapeBox(n)
SetObject3DPhysicsDamping(n,0,0)
SetObject3DPhysicsFriction(n,f)
Type sMob
Obj as integer
IsAttacked as integer
CibleOK as integer
CibleX as integer
CibleY as integer
EndType
nb = 5
dim mob[nb] as sMob
For i=0 to nb
//Cube[i] = InstanceObject(2)
mob[i].Obj = CloneObject(3)
n = mob[i].Obj
SetObjectPosition(n,2,20+2.5*i,0)
SetObjectColor(n,120,120,0,255)
Create3DPhysicsDynamicBody(n)
SetObjectShapeBox(n)
SetObject3DPhysicsDamping(n,0,0)
SetObject3DPhysicsMass(n,m)
SetObject3DPhysicsFriction(n,f)
SetObject3DPhysicsMaxLinearVelocity(n,0.1)
SetObject3DPhysicsRollingFriction(n,f)
next
// Camera
SetCameraPosition(1,0,30,-35)
do
Print( ScreenFPS() )
Step3DPhysicsWorld()
if GetPointerState()
X# = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() ) * 10000
Y# = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() ) * 10000
Z# = Get3DVectorZFromScreen( GetPointerX(), GetPointerY() ) * 10000
X# = X# + GetCameraX(1)
Y# = Y# + GetCameraY(1)
Z# = Z# + GetCameraZ(1)
obj=ObjectRayCast(4,getcamerax(1),getcameray(1),getcameraz(1),x#,y#,z#)
if obj
n=0
x1=GetObjectRayCastX(n)
y1=GetObjectRayCastZ(n)
SetObjectPosition(2,x1,1,y1)
walk = 1
endif
endif
// save the old position of the player
old_x = GetObjectX(1)
old_y = GetObjectY(1)
old_z = GetObjectZ(1)
move = 0
// if we can walk
if walk =1
if old_x <> x1 or old_z <> y1
speed# =0.1
move=1
if abs(old_x-x1)<=2
old_x = x1
endif
if abs(old_z-y1)<=2
old_z = y1
endif
SetObjectLookAt(1,x1,0,y1,0)
else
move =0
walk = 0
endif
if move =1
MoveObjectLocalZ(1,speed#)
// SetObject3DPhysicsLinearVelocity(
/*
// get the new position of the sphere
new_x = GetObjectX(1)
new_y = GetObjectY(1)
new_z = GetObjectZ(1)
// sphere cast between the old and new positions of the sphere
object_hit = ObjectSphereSlide(0,old_x,old_y,old_z,new_x,new_y,new_z,1)
// the sphere has collide with a box then calculate sphere new position to give sliding collision
// we do not need to know the Y component of the collision as the sphere only moves on the xz plane
if object_hit <> 0 and object_hit <> 5
x2 = GetObjectRayCastSlideX(0)
z2 = GetObjectRayCastSlideZ(0)
SetObjectPosition(1, x2, new_y, z2)
// SetObjectLookAt(1,x2+180,2,z2+180,0)
SetObjectRotation(1,GetObjectAngleX(1),GetObjectAngleY(1)+1,GetObjectAngleZ(1))
endif
*/
endif
endif
For i=0 to nb
n = mob[i].obj
x0 = GetObjectX(n)
z0 = GetObjectZ(n)
Print(str(x0)+"/"+str(GetObjectY(n))+"/"+str(z0))
if abs(x0-GetObjectX(1))<=5 and abs(z0-GetObjectZ(1))<=5
mob[i].IsAttacked = 1
endif
if mob[i].IsAttacked = 1
Mob[i].CibleX = GetObjectX(1)
Mob[i].CibleY = GetObjectZ(1)
if abs(x0-Mob[i].CibleX) <= 1
Mob[i].CibleX = x0
endif
if abs(z0-Mob[i].CibleY) <= 1
Mob[i].CibleY = z0
endif
if x0 <> Mob[i].CibleX or Mob[i].CibleY <> z0
SetObjectLookAt(n,Mob[i].CibleX,0,Mob[i].CibleY,0)
MoveObjectLocalZ(n,speed#)
endif
SetObjectRotation(n,0,GetObjectAngleY(n),0)
endif
Next
Sync()
loop
Someone knows how I can do that ?
Thank you.
http://www.dracaena-studio.com