Jump to content

Stona Persona

Members
  • Posts

    13
  • Joined

  • Last visited

Posts posted by Stona Persona

  1. CamOffset = -5
    CamRot = 0
    CamHeight = 2
    
    function Script:Start()
    	
    	PlayerCamera = Camera:Create()
    	
    	
    	
    	
    end
    
    
    
    function Script:UpdateWorld()
    	
    	PlayerCamera:SetPosition(self.entity:GetPosition().x, self.entity:GetPosition().y + CamHeight, self.entity:GetPosition().z + CamOffset)
    	local window = Window:GetCurrent()
    	local context = Context:GetCurrent()
    	
    	window:SetMousePosition(context:GetWidth()/2, context:GetHeight()/2)
    
    	mx = context:GetWidth()/2
    	my = context:GetHeight()/2
    
    	CurrMPos = window:GetMousePosition()
    
    	mxdiff = Math:Clamp(CurrMPos.x - mx,-45,45)
    	
    	PlAngle = Math:CurveAngle(self.entity:GetRotation().y + mxdiff, self.entity:GetRotation().y , Time:GetSpeed())
    	local move = 0
    	local strafe = 0
    	
    	self.entity:SetInput(PlAngle, move, strafe)
    	
    
    end

     

    Hello guys, so, i have this above code where im trying to get an entity to rotate around its Y-axis when i move the mouse from side to side. It kinda works but the rotation is not smooth and the entity just jumps to rotation values instead of rotating to them smoothly. 

    What am i doing wrong there? Thanks in advance for your time. 

    • Like 1
  2. 59 minutes ago, SpiderPig said:

    I think the pick idea would work better.  Like you say, you would have to roughly aim at the enemy first.  Are you using C++ or LUA?  I haven't used Leadwerks in ages and right now I'm pressed for time, but here's the general idea (syntax is off, I'm using the tippy top of my head) :P

    Something like this perhaps... there would be more to it than this.

    float radius = 0.25f;
    PickInfo pick_info;
    Vec3 player_pos = player->GetPosition(true);
    Vec3 target_position = camera->UnProject(screen_centre);//or Project??  I forget
    
    if(Pick(player_pos, target_pos, pick_info, radius) == true){
    	if(pick_info.entity == enemy) {
         	Vec3 enemy_pos = pick_info.entity->GetPosition(true);
          	player->Point(enemy_pos + an_offset_maybe)
        }
    }

    You could use distance as well and get the angle to each enemy to figure out the closest in distance and angle...

    Thanks for the quick answer, i think i try it out like this. Im using LUA btw, should ve mentioned in first post. Since i use the player to cast a ray out in the world to detect stuff, so i dont plan to use a crosshair i think i wont need the Camera:UnProject but just get the position of the enemy from the pick. 

    The thing is im trying to figure stuff out for so long now i kinda got tired of trying stuff that doesnt work out in the end, so im very thankful for your information. 

    I think ill try to use the pick i already have when aiming and shooting to make it lock onto the picked enemy.

    • Like 1
  3. Greetings fellas, 

    im currently trying to figure out how to build a player system like in the PS1 era survival horror games like Resident Evil for example. 

    So far i got static cameras to switch, tank controls and a very basic shooting mechanic (hold down R mouse and press L mouse to shoot).

    But now im kinda stuck at how to approach a system that lets my player lock onto an enemy when aiming. Some help with pseudo code would be much appreciated.

    Would i try to get distances between player and the closest enemy entity or would i use a pick with maybe a bigger radius so you kinda have to roughly aim into the enemies direction and if pick hits the player is locked on? Im still trying to figure the code stuff out, so not a pro coder here. :D

  4. I have one question tho, sorry if it doesnt fit in here. Will Leadwerks still get some love or being kept alive, since im still fiddling around with it and it wouldnt be money-efficient for me to pay monthly for a tool i wouldnt be using that often. Im still trying to get my head around LW, so i just want to know if its still worth spending the time on it. Thanks in advance. 🙂

  5. On 10/13/2022 at 4:18 PM, Alienhead said:

    2 weeks into the competition so far..   My idea is finally starting to materialize and actually feeling somewhat like a game. :) Over the next 2 weeks I'll have the game mechanics finished leaving me a solid month for UI and polishing.   Onward march !!!

    Wish you best of luck! Excited to see what you managed to put together after the competition. 

    • Like 1
  6. 1 hour ago, DoomSlayer said:

    Oh man, I miss the Leadwerks Games Tournament. 
    Maybe after Ultra releases, we can have a new friendly game contest.

    Good luck Alienhead :)

    Id even be ready to spend 50 bucks for the winner if such contest would happen.  Im still a coding noob because i was jumpy af tried this engine, this language and so on but now since i tried em all im stuck with LW and therefore i think its more than worth to push the engine and also the community. 

    So yeah, im ready to cash in to make such contest happen anytime. 

     

    Cheers.

    • Like 2
  7. On 3/31/2022 at 2:10 PM, wildcherrii said:

    Hi thanks for your reply.   I've tried the fps code prior to posting but I think something is wrong internally.  To test this I made a blank project,  in the MAIN.LUA script ( top level ),  before the main While/Do loop i added this code - 

    lo=Prefab:Load("Prefabs/Effects/smoke.pfb")
    lo:Play()

    then ran it,  it does the same thing as my normal project, it says :

    "C:/Project/Scripts/Main.lua" : 17 : attempt to call method 'Play' (a nil value)

    The variable lo is not in a function but above the main while/do loop in main.lua so it's globally declared I would presume.   Do i need to declare the variable as an Emitter:type or something ?

    Running a debug on the variable the text returned was showing a loaded entity - userdata: 0x0432dba8

    What i learned from my little experience is that some commands only work inside functions but not outside of them. im getting a lot of these and then i switch some commands around like put them in a function or take something out of it so it isnt in a function and eventually, atleast for now, i ended up getting stuff to work. Maybe it helps you a bit, im a coding noob, so maybe im just talkin BS here, but atleast for me it worked out most of the time, even tho it can be tedious.

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

     

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

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

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

×
×
  • Create New...