Jump to content

Collision Issues


Cole Chapman
 Share

Recommended Posts

I used Marleys Third Person Cam tutorial and made a Player Type but I cannot get collisions to work. The only differences as far as I can tell is I did not use (and do not want to) use LUA functions and I use MaxGUI(though I cannot see how that would make a difference)

 

The Code:

 

SuperStrict


Framework Leadwerks.Engine
Import "Framework.BMX"
Import MaxGUI.MaxGUI
Import MaxGUI.Drivers
Import BRL.EventQueue
RegisterAbstractPath("C:\Leadwerks Engine SDK")
GCSetMode(2)


Global FW:TFramework
Local GEWindow:TGadget
Local GEWindowX:Int 'Null (WINDOW_CENTER)
Local GEWindowY:Int 'Null (WINDOW_CENTER)
Local GEWindowW:Int = 800
Local GEWindowH:Int = 600
Local GEWindowStyle:Int = WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_MENU|WINDOW_STATUS|WINDOW_CENTER
Local Canvas1:TGadget

Global Terrain:TTerrain
Global TerrainText:TTexture
Global Light:TLight

DebugPhysics(1)

Type TPlayer
Global Current:TPlayer
Field Controller:TController
Field Move:Float
Field Strafe:Float
Field CamRotation:TVec3
Field MX:Float
Field MY:Float
Field Jump:Float
Field Position:TVec3
Field Body:TEntity
Field CamY:Float
Field CamZ:Float

Function Create:TPlayer()
	Local Player:TPlayer = New TPlayer

	Player.Move:Float = 0.0
	Player.Strafe:Float = 0.0
	Player.CamRotation:TVec3 = Vec3(0)
	Player.MX:Float = 0.0
	Player.MY:Float = 0.0
	Player.Jump:Float = 0.0
	Player.CamY:Float = 0.0
	Player.CamZ:Float = 0.0

	Player.Controller = CreateController(2.0)

	PositionEntity(Player.Controller, EntityPosition(FW.Main.Camera))
	EntityType(Player.Controller, 3)
	SetBodyMass(Player.Controller, 10.0)
	SetBodyBuoyancyMode(Player.Controller, 0)
	Collisions(1, 3, 3)

	Player.Body:TEntity = CreateCube(Player.Controller)
	ScaleEntity(Player.Body, Vec3(0.5, 1.8, 0.5))
	Return Player
EndFunction

Method Update()
	Self.MX = Curve(MouseX() - GraphicsWidth() / 2, Self.MX, 6)
	Self.MY = Curve(MouseY() - GraphicsHeight() / 2, Self.MY, 6)
	MoveMouse(GraphicsWidth()/2, GraphicsHeight()/2)
	Self.CamRotation.X = Self.CamRotation.X + Self.MX / 10.0
	Self.CamRotation.Y = Self.CamRotation.Y - Self.MX / 10.0

	RotateEntity(FW.Main.Camera, Self.CamRotation)

	If Self.CamRotation.X > 90.0 Then Self.CamRotation.X = 90.0
	If Self.CamRotation.X < -20.0 Then Self.CamRotation.X = -20.0

	Self.Move = KeyDown(KEY_W) - KeyDown(KEY_S)
	Self.Strafe = KeyDown(KEY_D) - KeyDown(KEY_A)
	Self.Jump:Float = 0.0

	If KeyHit(KEY_SPACE) And Not ControllerAirborne(Self.Controller) Then
		Self.Jump = 4.0
	EndIf
	If KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT) Then
		Self.Move = Self.Move * 3.0
		Self.Strafe = Self.Strafe * 3.0
	EndIf

	PositionEntity(FW.Main.Camera, Vec3(Self.Controller.Position.X, Self.Controller.Position.Y + 0.8, Self.Controller.Position.Z))
	Self.CamY = 0.5
	If MouseZ() > 0 Then FlushMouse()
	If MouseZ() < 0 Then Self.CamY = 0.0
	Self.CamZ = Curve(MouseZ(), Self.CamZ, 10)
	MoveEntity(FW.Main.Camera, Vec3(0, Self.CamY, Self.CamZ))

	UpdateController(Self.Controller, Self.CamRotation.Y, Self.Move * 3, Self.Strafe * 3, Self.Jump, 0.5)
EndMethod
EndType


GEWindow:TGadget = CreateWindow("GE", GEWindowX, GEWindowY, GEWindowW, GEWindowH, Null, GEWindowStyle)
Canvas1:TGadget = CreateCanvas(0, 0, ClientWidth(GEWindow), ClientHeight(GEWindow), GEWindow)

SetGadgetLayout(Canvas1, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED)
SetGraphics(CanvasGraphics(Canvas1))
ActivateGadget(Canvas1)
EnablePolledInput()


FW:TFramework = CreateFramework()
If Not FW RuntimeError "Failed to Initialize Engine"



Terrain = CreateTerrain(2048)
LoadTerrainHeightmap(Terrain, "Terrain.raw")
TerrainText = LoadTexture("TerrainGrass.dds")
SetTerrainTexture(Terrain, TerrainText, 0, 0)


PositionEntity(FW.Main.Camera, Vec3(0.0, 1000.0, 0.0))
Light:TLight = CreateDirectionalLight()
PositionEntity(Light, Vec3(0.0, 350.0, 0.0))
RotateEntity(Light, Vec3(45,45,0))
CameraRange(FW.Main.Camera, 0.1, 750.0)

SetSkyBox(LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat"))
SetBackGroundColor(Vec4(1,1,1,1))
SetFarDOF(1)
SetFarDOFStrength(1)
SetFarDOFRange(600.0, 750.0)


Global MainPlayer:TPlayer
MainPlayer:TPlayer = TPlayer.Create()
If Not MainPlayer RuntimeError "Failed to Create Player."

Repeat

While PeekEvent()
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_WINDOWSIZE
			SetGraphics CanvasGraphics(Canvas1)
	EndSelect
Wend

MainPlayer.Update()

If KeyDown(KEY_ESCAPE) Then End

FW.Update()
FW.Render()

SetBlend(1)
DrawText(MouseX(), 0, 10)	
SetBlend(0)	

Flip(0)
Forever

GCCollect()
End

Link to comment
Share on other sites

close Richard... that line is the problem though... he is setting the collision response to something that doesn't exist.

Collisions

BlitzMax: Collisions( collisionType1, collisionType2, collisionResponse )

Sets the collision response for collision type 1 and 2.

0 - no collision (default)

1 - sliding collision

2 - no-response collision; a collision is recorded, but the objects will pass through each other.

 

so the line should read:

Collisions(1, 3, 1)

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

Collisions only have three parameters, The first two are (I BELIEVE) Entity Groups in a way and the third is what happens if Entities from those groups collide. I have tried

Collisions(1, 3, True)

Collisions(1, 3, 1)

Collisions(1, 3, 2)

Collisions(1, 3, 3)

 

And I have also assigned EntityType(Terrain, 1,2,3,etc with no such luck.

Marleys code works though and I am hoping its not because of the LUA stuff

Link to comment
Share on other sites

well first thing is that you are turning the controller into a bullet by setting its position 1000 meters above the terrain... so by the time it hits the terrain its going so fast it passes through the terrain. Try setting the camera only 1 or 2 meters in the Y axis or try setting swept collision for the controller. Also along with the setting the collisiontype for the controller you must also set the collision type for the terrain. Then you have to set the collision response for each possible collisiontype.

 

Also I am not sure what your hesitation is with using the lua scripts, but they work great for setting up the normal parameters like collisiontypes/responses. In any case, you should probably try just loading a SBX with LoadScene instead of trying to create a terrain. You have multiple issues here - collisions, camera rotation/placement, DOF set so everything is a blur, etc... that just compound your problems when trying to troubleshoot. If you attempt one thing at a time and rely on proven methods first, then it makes troubleshooting your code alot easier on yourself... just a helpful suggestion... :)

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

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...