Jump to content

Sweetgebus

Developers
  • Posts

    17
  • Joined

  • Last visited

Posts posted by Sweetgebus

  1. 3 hours ago, CJO Games said:

    Have a look at the attached fps script - it's a working example of how jump is integrated - it seems counter-intuitive to rewrite what is already available and what is already working...

    Self punishment of learning is all. I took your advice though and after a couple of hours of studying and removing functions that were needed for my idea, I got it working.

    • Like 2
  2. 4 minutes ago, Josh said:

    You need more parameters for SetInput:
    https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_SetInput

    Syntax

    • SetInput(number angle, number move, number strafe=0, number jump=0, bool crouch = false, float maxaccel = 1, float maxdecel = 0.5, bool detailed = false, float maxrotationspeed=5.0)

    Parameters

    • angle: the angle the character faces.
    • move: the forward movement of the character.
    • strafe: the horizontal movement of the character.
    • jump: the jumping force to apply.
    • crouch: set to true for crouching mode (included for future development)
    • maxacceleration: the maximum acceleration the character may use to speed up.
    • maxdecelleration: the maximum acceleration the character may use to slow down.
    • detailed: set this to true for characters that have a camera mounted on them. This will provide more accurate physics, but will also be more expensive to calculate.
    • maxrotationspeed: this is the maximum speed the entity can turn, in degrees per physics step.

    I'm a little confused on that part. In the doc it just shows angle,move and strafe used.

    player:SetInput(0,move,strafe)

     

     

  3. 36 minutes ago, CJO Games said:

    I think the best way to answer this question is to ask another - what is it you want your created model to do? Assuming you want to create a player character(?) the first thing to do is place it in the editor (graphically) and then attach a player script to it using the script tab in the editor (you can see it in your post above) - I think you are trying to set up a player character programmatically, which is fine but not necessary; indeed, the graphical option (drag and drop) is an easier start and gives you the chance to get a working prototype up and running. I have found that learning my way around code comes easier to me by looking at and adapting ready built scripts - seeing how they work and then understanding that feels like a more natural approach - but of course this all comes don to personal preference.

    In terms of what I think you are trying to do above you might start with the included FPS script and adapt it for your needs - as an example - here is my own adapted FPS script which includes a number of commented sections where I have tried to understand what each part is doing and also has some other changes that I have found useful/necessary for my own projects.

    I've also attached a script I'm currently working on which is designed with a space exploration game in mind and which I have adapted from the spectator script included with Leadwerks.

    Hopefully these will be helpful to you. In terms of LUA in general, Leadwerks is more of an implementation of it than its purest form so although its useful to look up other sources it will have differences too. I have actually found that AppGameKit Studio has been useful because although it is a BASIC language its structure and syntax are similar to the way LUA in Leadwerks works. Also useful are the Skyline Game Engine  which also uses LUA but in a different form and Game Guru Max which has its own quirky implementation of LUA.

    FPSPlayer.lua 33.94 kB · 1 download BridgeCam.lua 9.89 kB · 0 downloads

    I've studied the stock fps script and attempted to break it down. In my code snippet I'm fighting just to get my character to jump. I figured I would make a simple platformer where my character, or cube in the case has a constant move speed. Add in gaps and such for you to have to jump over. And as I learn I could add things like speed boosts and such. my script is attached to my character cube.  

  4. Let me preface by saying that I have no experience in coding, aside from basics. As I am sure everyone has been at one point, I don't even know how to learn it. Is the docs provided in Leadwerks enough for the non programmer to learn? Do I need to learn Lua outside of leadwerks in order to learn to script within it?  I ask this loosely as I know that knowledge is king.  If I base my learning purely off the script documentation provided, is that enough to make a game? 

    Example of my current headache regarding set input.

     

    function Script:Start()
        self.camera = Camera:Create()
        self:UpdateCamera()
        player = Pivot:Create()
    end

    function Script:UpdatePhysics()
        local jump = ((window:KeyDown(Key.Space) and 1 or 0))
        player:SetInput(0,jump)
    end


    function Script:UpdateCamera()
        self.camera:SetRotation(20,90,0)
        self.camera:SetPosition(self.entity:GetPosition())
        self.camera:Move(0,0,-3)
    end


    function Script:UpdateWorld()
        self:UpdateCamera()
    end

    image.png.ba08514192c6834d3755747194603397.png

    Looking at the the documentation, the example code for SetInput shows the player, world, and controls being created via script, rather than using a model and the editor to create the world. I struggle with understanding how to implement it to work with created models.  As you guys would probably be able to understand why, the above code is incorrect. I'm sure its simple, but even the most simple task is a nightmare for me. I've wanted to learn to script for over a decade and have made numerous attempts to make sense of it all. The internet is flooded with resources for learning, but that even seems to make it even more overwhelming. I once had a friend who was a coder and for a short time he was great at helping me with trying to learn, but unfortunately he passed away. 

    I appreciate in advance for your responses. 

     

  5. Just now, Sweetgebus said:

    is this specific to ultraengine? or is the same for leadwerks 4.6?

     

    function Script:UpdatePhysics()

        self.entity:AddForce(0,0,-.5)

        if window:KeyHit(Key.Space) then
            self.entity:AddForce(0,10,0,true)
        end
    end 
     

     

  6. Hello, I'm attempting to learn lua script and have been battling what I'm sure is a simple issue. I have my cube"Player" that I have made to be able to jump via key press. With the current logic, I can continue to press the key and the player will never hit the ground. I would like to be able to double jump and then wait for x amount of seconds before doing it again. I was looking into "Wait" but I'm not having luck with it either. 

  7. 5 minutes ago, Josh said:

    Instead of defining a local variable for speed, do this:

    
    function Script:UpdatePhysics()
    	if self.speed == nil then self.speed = 0 end --initialize self.speed to zero if it is undefined
    	local gas = false
    
    	-- Movement / Input
    	if window:KeyDown(Key.W) then
    		gas = true
    		self.entity:Move(0,0,self.speed)
    	end	
    	if gas == true then
    		self.speed = self.speed + 1
    	else
    		self.speed = self.speed - 1
    		if self.speed < 0 then self.speed = 0 end
    	end
    end

    This seems to work, I haven't seen the self.speed command before. Not sure how it works.  Never the less, I appreciate the help with this. I should be able to manipulate this a bit to get the results I'm looking for, such as not stopping immediately after releasing W.

  8. Now that I know its broken I'm trying to find a work around. I'd like to have an object  gain speed over time. Below is what I've been attempting, but haven't been successful.

    function Script:Start()
    	self.camera = Camera:Create()
    	self:UpdateCamera()
    end
    
    function Script:UpdateCamera()
    	self.camera:SetPosition(self.entity:GetPosition())
    	self.camera:SetRotation(self.entity:GetRotation())
    	self.camera:Move(0,3,-4)
    end
    
    function Script:UpdatePhysics()
    	local speed = 0
    	local gas = false
    
    -- Movement / Input
    	if window:KeyDown(Key.W) then
    		gas = true
    		self.entity:Move(0,0,speed)
    		else gas = false
    			while gas == true do
    				speed = speed +1
    		end
    	end
    end
    
    function Script:UpdateWorld()
    self:UpdateCamera()
    end

     

  9. 6 hours ago, Josh said:

    Hi, I am sorry for this but the vehicle does not currently work.

    There were changes in the physics engine we use, and some of the changes were things we really needed, but it also broke the vehicles system.

    I am looking into an updated system. The code is embedded in a demo and it' will take some time to pull out and integrate correctly.

    Thats unfortunate, I've been losing mind for the past few weeks trying to make it work.

     

  10. 30 minutes ago, Yue said:
    
    Script.chassis = nil --entity "Chassis"
    Script.wheel0   = nil --entity "Wheel0"
    Script.wheel1   = nil --entity "Wheel1"
    function Script:Start()
    	
    	self.vehicle = Vehicle:Create(self.entity)
    	self.vehicle:AddTire(self.wheel0,false)
    	self.vehicle:AddTire(self.wheel1,false)
    
    end
    
    
    
    function Script:UpdateWorld()
     
    end
    
    
    
    function Script:UpdatePhysics()
    self.vehicle:SetGas(5000)		
    end

    Hello, try this simple.

    does the model have to have wheels? like a hovercraft for example

     

  11. Hello, I've been dissecting the vehicle script trying to understand how it work. Unfortunately despite weeks of headache I've gotten no where. Below is  the Lua script that I pieced together.  I do not get any errors, but my logic must be wrong. I can run the program, but nothing happens when the key is pressed. I've very new to scripting and looking for any help I can get. I appreciate it in advance. 

    Script.acceleration=200 --float acceleration
    function Script:Start()
    	self.vehicle = Vehicle:Create(self.entity)
    --Create and Update Camera
    	self.camera = Camera:Create()
    	self:UpdateCamera()
    end
    
    function Script:UpdateCamera()
    --Update Camera Postion and Rotation
    	self.camera:SetPosition(self.entity:GetPosition())
    	self.camera:SetRotation(self.entity:GetRotation())
    	self.camera:Move(0,4,-6)
    end
    
    function Script:UpdatePhysics()
    	local groundspeed = self.entity:GetVelocity()
    	groundspeed = groundspeed:xz()
    	groundspeed = groundspeed:Length()
    
    	local gas = 0
    	local window = Window:GetCurrent()
    	if window:KeyDown(Key.W) then gas = gas + self.acceleration end
    	self.vehicle:SetGas(gas)
    end
    

     

  12. Hello, new to leadwerks. I've been scratching my head trying to figure out had to addforce to an object in the direction of the camera. I've started out with leadwerks just attempting little things as people usually do. Right now I've got a gokart that I've been able to get moving, but the problem is when it turns, the direction of travel does not. I've utilized the Addforce command but cannot seem to figure out how to make it follow the direction the camera is pointing at the time.  I'm scripting lua, and anything help would be appreciated.

×
×
  • Create New...