Jump to content

3D Side Scroller problem


Stona Persona
 Share

Recommended Posts

Hey guys, i just recently started to dig into the Leadwerks coding and so far its getting on with the help of the docs and the forums but now i seem kinda stuck.

So, my problem is.. i set up the generic model as the player character and just added a simple CSG block as a platform for testing purposes. My character has a mass of 1, falls from the air and lands on the platform, all cool. But he doesnt fall further down from the platform or collides with any "walls" i placed in for testing. 

Character is set up as character controller, walls and floors are set up as rigid bodies with collision type scene (tried prop and others also)

If i set the mass to every block as lets say 2, then physics start to work, makes sense. But how do i make platforms that are static without falling with the character into the endless abyss. 

I made a little script to attach to the boxes which disables the gravity for the entity, it stays in place, but the character is still able to "push it" and it starts to jitter and apparently the character slides off the platform and disappears into the shadow realm. Next i told the box to get its initial position at Script:Start and apply it constantly in the Update:Physics function. Ppl more experienced with code will prolly roll on the floor now with cramps in their stomach but yeah. xd

 

Some little help would be very appreciated. 

Link to comment
Share on other sites

Using scene collision type is correct. The character controller isn't able to slide on it's own, you need to use prop type if you want it sliding on an angled platform.

I don't know why it doesn't collide with walls, you should record a video and attach your character script.

  • Thanks 2
Link to comment
Share on other sites

24 minutes ago, Genebris said:

Using scene collision type is correct. The character controller isn't able to slide on it's own, you need to use prop type if you want it sliding on an angled platform.

I don't know why it doesn't collide with walls, you should record a video and attach your character script.

Hey, thanks for the answer. What i want to achieve are just platforms i could build a level with but with collision for the player and they have to be static, like floating in the "air" so the player could walk on them. 

 

I upload a video where i try to show my issue as best as possible. 

Heres the code for the player 

Script.CamOffset = Vec3() --vec3 "Camera Offset"
Script.PlayerMoveSpeed = 5 --float "Player Movement Speed"
--[[Script.isOnFloor = true]]

function Script:Start()
	PlayerPos = self.entity:GetPosition()
	camera1 = Camera:Create()
	camera1:SetPosition(PlayerPos.x, PlayerPos.y + self.CamOffset.y ,PlayerPos.z - self.CamOffset.z)
	
end

--[[
function Script:UpdateWorld()
	
end
]]

--[[
function Script:IsOnFloor()
	
	if isOnFloor(true) then
		self.entity:SetGravityMode(false)
	elseif isOnFloor(false) then
		self.entity:SetGravityMode(true)
	end
end
]]
function Script:UpdatePhysics()
	
	

	local CamPosUpdate = self.entity:GetPosition()
	camera1:SetPosition(CamPosUpdate.x, CamPosUpdate.y + self.CamOffset.y, CamPosUpdate.z - self.CamOffset.z)
	
	
	if window:KeyDown(Key.D) then
		self.entity:Move(self.PlayerMoveSpeed,0,0)
		
	elseif window:KeyDown(Key.A) then
		self.entity:Move(-self.PlayerMoveSpeed,0,0)	
		
	end
	
	--[[if self.entity:GetKeyValue("Collision Type","Prop") then
		isOnFloor = true
		
	else
		isOnFloor = false
		
	end]]
	
	
end

 

The isOnFloor stuff was just me trying something out. Below is the script i attached to one of the boxes in the video to kinda "keep it in place" every physics update, but that causes more headache tbh. 

Script.gravitymode = false --bool "Gravity Mode"

function Script:Start()
if self.gravitymode then
	self.entity:SetGravityMode(true)
else
	self.entity:SetGravityMode(false)
end
PosLock = self.entity:GetPosition()
RotLock = self.entity:GetRotation()
self.entity:SetMass(2)
end


--[[
function Script:UpdateWorld()
	
end
]]


function Script:UpdatePhysics()
	self.entity:SetPosition(PosLock.x, PosLock.y, PosLock.z)
	self.entity:SetRotation(RotLock.x, RotLock.y, RotLock.z)
end

 

1609157828_2022-03-3013-31-06.mkv

Link to comment
Share on other sites

2 hours ago, Stona Persona said:

If i set the mass to every block as lets say 2, then physics start to work, makes sense. But how do i make platforms that are static without falling with the character into the endless abyss. 

Disable the mass when the platform reached it's destination. You also should be using the slider joint. See the platform and sliding door script included in the base template.

 

  • Thanks 2

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

14 minutes ago, reepblue said:

Disable the mass when the platform reached it's destination. You also should be using the slider joint. See the platform and sliding door script included in the base template.

 

Thanks for the reply, but im not at the stage with moving platforms yet, i cant get the "platforms" i already have to stay where they are and still behave like solid objects with collisions for the player. Everything just falls into darkness or stays in place but doesnt collide. 

 

I probably could use the terrain and build my levels on that but there must be a way to make the CSG boxes float in air but still be solid with collision and act as a ground themselves. 

Link to comment
Share on other sites

You can't use entity:Move for the character, it's only for non physical objects because it ignores collision. For character, you use enitity:SetInput. Look how character is done in FPS example project. You can also see how walls and platforms are set up there.

self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true)

https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_SetInput

 

 

You don't need to do SetGravityMode, all you need is static boxes with scene type and correct character movement script.

  • Thanks 2
Link to comment
Share on other sites

7 minutes ago, Genebris said:

You can't use entity:Move for the character, it's only for non physical objects because it ignores collision.

TYVM, that is actually good to know, since the documentation didnt mention anything like that. Now it all makes sense why stuff is behaving strange af. 

 

Link to comment
Share on other sites

Yeah, documentation must be really confusing for new users, you are not the only person who had trouble with this recently. I suggest you just go off of example projects, they should have everything you need to make a basic game.

 

Notice how character controller and prop controller are different things and use different methods to move. I suggest you start with character controller while you learn and rely on FPS example.

  • Thanks 2
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...