Jump to content

Einlander

Members
  • Posts

    778
  • Joined

  • Last visited

Posts posted by Einlander

  1. I have a sphere brush object that I am using needs to use entity navigation (be a character controller) but also needs to float. When i set gravity mode to false, it hovers but it doesn't move. When gravity mode is default, it falls to the floor but then navigates.

     

    You also have the choice of adding the script to a pivot, and the sphere to the pivot at the height you want. This will let it appear as if it's floating while the character controller is actually on the ground.

  2. You would need to use add force to use physics to push your controller where you want. I'll have a go at adding a jetpack to the default fps controller tomorrow.

     

    ---Edit--

     

    So it seems that with the 'Character Physics' mode Leadwerks applies different rules to the entity. Thusly this means that you can not reliably nullify the falling of the Character controller with proper math.

     

    I'm still working on getting the Jetpack to work no matter the mass or gravity with the character controller. Cross your fingers.

    • Upvote 2
  3. Find the exe folder. In an empty area of the window hold shift and right click. Click start command prompt her. Type your games exe name.

     

    Also make sure your app/main.lua file is actually loading the right map. By default it's start.map

  4. I just re-checked, you are right macklebee. If it is reachable it will move to that point regardless of how it is called. Honestly I think it should not move if you have it in an if then statement, but that's another matter.

  5. Well I jsut pressed ctrl+a, choosed face instrument and pressed C on the right side of screen.

     

    I wouldn't trust it too much, there are bugs that make it completely unrecoverable. Rotating a prefab is one of the almost unrecoverable bugs.

    • Upvote 1
  6. You can use Gimp, Krita, Paint.net, Fire Alpaca and many, many, more free and or open source tools to add an alpha texture. It should be similar to the photoshop method but there are some program specific terms. Photoshop is just a generic term/tool now, the same way Xerox is.

  7. I've been staring at this code for way too long and now I need different brains to look at it. This is the beginnings of a 3rd person character controller. I am now working at adding mouse look features but there seems to be a bug when the camera is at specific angles, notable y45 and y270. At those specific locations the camera glitches out.

     

    I will give it another try tomorrow, and no I don't want to create a pivot and anchor the camera to it and spin that -_-

     

    
    

     

    --[[

    Title: Third Person Controller

    Author: Einlander

    Start Date: 1-30-2016

    Version: .01

    Description: Script to control Player in 3rd person with keyboard and mouse

    Notes:

    This script is designed to mimic classical 3rd person game controls:

    *Look with mouse

    *Move with WASD

    *Follow Player as they move

    ]]--

     

    Script.Cam =nil --entity "Camera"

     

    Script.moveSpeed = 2.5 --float "Move Speed"

    Script.speedMultiplier = 1.5 --float "Run Multiplier"

    Script.strafeSpeed = 4 --float "Strafe Speed"

    Script.jumpForce = 8 --float "Jump Force"

     

    function Script:Start()

    self.input={}

    self.unitangle = Vec3()

    self.anglemagnitude = nil

    end

     

     

    --[[

    function Script:UpdateWorld()

     

    end

    --]]

     

    function Script:UpdatePhysics()

    local movex=0

    local movez=0

    self.input[0]=0

    self.input[1]=0

    local playerMovement = Vec3()

    -- I learned the boolean shortcuts from my years programming on a Casio Graphing Calculator

    self.input[1] = self.input[1] + ((window:KeyDown(Key.W) and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0))

    self.input[0] = self.input[0] - ((window:KeyDown(Key.A) and 1 or 0) - (window:KeyDown(Key.D) and 1 or 0))

    playerMovement.z = self.input[1] * self.moveSpeed

    -- Strafing

    playerMovement.x = self.input[0] * self.moveSpeed

    if self.carryingEntity == nil and window:KeyDown(Key.Shift) then

    playerMovement.z = playerMovement.z * self.speedMultiplier

    -- Run while Strafed

    -- playerMovement.x = playerMovement.x * self.speedMultiplier

    end

     

    local jump = 0

    if window:KeyHit(Key.Space) and self:IsAirborne() == 0 then

    jump = self.jumpForce

    playerMovement = playerMovement * 1.6

    end

     

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

     

    local startpos = Vec3( self.entity:GetPosition(true).x, self.entity:GetPosition(true).y + 5 , self.entity:GetPosition(true).z -5 ) -- y distance to get above players head, z - distance we want from player

    local endpos = Vec3()

     

    -- rotate the starting position (where the camera is at) around the player position

     

    if self.rot == nil then self.rot = 0 end

    self.rot = self.rot+.5

     

    local finalpos = Vec3()

    finalpos = self:rotateX3D({startpos},self.entity:GetPosition(true) , 0)[1]

     

     

    finalpos = self:rotatePointY({finalpos},self.entity:GetPosition(true) , self.rot)[1] -- when self.rot ~ 45 or 270 it flips just for that 1 angle

     

     

    -- set camera at the final rotated positon

    self.Cam:SetPosition(finalpos)

     

     

    -- make camera look at player

    local lookAt = self:LookAt(self.entity:GetPosition(true))

    lookAt.z = 0 -- THIS LINE IS IMPORTANT. DO NOT REMOVE IT, IF YOU DO IT WILL CAUSE A JUMP WHEN THE Z ANGLE CHANGES FROM NEGATIVE TO POSITIVE OR VICE VERSA

    self.Cam:SetRotation(lookAt,true)

    end

     

    function Script:IsAirborne()

    return self.entity:GetAirborne() and 1 or 0

    end

     

    function Script:LookAt(lookAt)

    --http://www.leadwerks.com/werkspace/topic/10191-short-example-of-mathatan2/page__hl__lookat

    --http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point

    --http://leadwerks.wikidot.com/wiki:face-entity

     

    --// Calculate angle from point A towards point B

    local tv = lookAt - self.Cam:GetPosition(true)

     

    local tRoty = Math:ATan2(tv.x, tv.z)

    local tRotx = 0

    if lookAt.z >= self.Cam:GetPosition(true).z then

    tRotx = -Math:ATan2(tv.y* Math:Cos(tRoty), tv.z)

    else

    tRotx = Math:ATan2(tv.y* Math:Cos(tRoty), -tv.z)

    end

    tRotz = Math:ATan2( Math:Cos(tRotx), Math:Sin(tRotx) * Math:Sin(tRoty) )

    return Vec3(tRotx,tRoty,tRotz-90)

    end

     

     

    function Script:Get3dDistance(pointa --[[as vec3--]], pointb--[[as vec3--]]) --[[as float--]]

    return math.sqrt((pointb.x - pointa.x)^2+ (pointb.y - pointa.y)^2+ (pointb.z - pointa.z)^2)

    end

     

    function Script:Get3dMagnitude(pointa --[[as vec3--]]) --[[as float--]]

    --http://www.fundza.com/vectors/normalize/

    return math.abs(math.sqrt((pointa.x * pointa.x)+ (pointa.y * pointa.y)+ (pointa.z * pointa.z)))

    end

     

    function Script:NormalizeVector(pointa--[[as vec3--]], length--[[as float--]])--[[as vec3--]]

    --Yes I know leadwerks has these functions built in somewhere, but sometimes you just need to learn what it is you are exactly doing

    --http://www.fundza.com/vectors/normalize/

    pointa.x = pointa.x / math.abs(length)

    pointa.y = pointa.y / math.abs(length)

    pointa.z = pointa.z / math.abs(length)

    return pointa

    end

     

    toRadians = function(degrees) return degrees / 180 * math.pi end

     

    function Script:rotatePointY(points, origin, degrees)

    local pointsout = {}

    for i = 1, #points do

    local point = Vec3(points.x,points.y,points.z)

    local x = origin.x + ( math.cos(toRadians(degrees)) * (point.x - origin.x) - math.sin(toRadians(degrees)) * (point.z - origin.z) )

    local z = origin.z + ( math.sin(toRadians(degrees)) * (point.x - origin.x) + math.cos(toRadians(degrees)) * (point.z - origin.z) )

    point.x = x

    point.z = z

    table.insert(pointsout, point)

    end

    return pointsout

     

    end

     

     

    function Script:rotatePointZ(points, origin, degrees)

    local pointsout = {}

    for i = 1, #points do

    local point = Vec3(points.x,points.y,points.z)

    local x = origin.x + ( math.cos(toRadians(degrees)) * (point.x - origin.x) - math.sin(toRadians(degrees)) * (point.y - origin.y) )

    local y = origin.y + ( math.sin(toRadians(degrees)) * (point.x - origin.x) + math.cos(toRadians(degrees)) * (point.y - origin.y) )

    point.x = x

    point.y = y

    table.insert(pointsout, point)

    end

    return pointsout

    end

     

    function Script:rotatePointX(points, origin, degrees)

    local pointsout = {}

    for i = 1, #points do

    local point = Vec3(points.x,points.y,points.z)

    local y = origin.y + ( math.cos(toRadians(degrees)) * (point.y - origin.y) - math.sin(toRadians(degrees)) * (point.z - origin.z) )

    local z = origin.z + ( math.sin(toRadians(degrees)) * (point.y - origin.y) + math.cos(toRadians(degrees)) * (point.z - origin.z) )

    point.y = y

    point.z = z

    table.insert(pointsout, point)

    end

    return pointsout

     

    end

     

    function Script:rotateX3D (points, origin, degrees)

    local pointsout = {}

     

    for i = 1, #points do

    local point = Vec3(points.x,points.y,points.z)

    local y = point.y;

    local z = point.z;

    point.y = origin.y + (y- origin.y) * math.cos(toRadians(degrees)) - (z - origin.z) * math.sin(toRadians(degrees));

    point.z = origin.z + (z- origin.z) * math.cos(toRadians(degrees)) + (y - origin.y) * math.sin(toRadians(degrees));

    table.insert(pointsout, point)

    end

    return pointsout

    end

     

     

    function Script:WrapAngle(angle)

    local currentrotation = angle

    if currentrotation.x < 0 then

    currentrotation.x = 359 - math.mod(currentrotation.x , 359)

    end

     

    if currentrotation.y < 0 then

    currentrotation.y = math.mod(currentrotation.y , 359)

    currentrotation.y = 359 - math.abs(currentrotation.y)

    end

     

    if currentrotation.z < 0 then

    currentrotation.z = 359 - math.mod(currentrotation.z , 359)

    end

     

    currentrotation.x = math.mod(currentrotation.x , 359)

    currentrotation.y = math.mod(currentrotation.y , 359)

    currentrotation.z = math.mod(currentrotation.z , 359)

    return currentrotation

    end

     

    --[[

    function Script:Collision(entity, position, normal, speed)

     

    end

    --]]

     

    --[[

    function Script:Draw()

     

    end

    --]]

     

    --[[

    function Script:DrawEach(camera)

     

    end

    --]]

     

     

    --This function will be called after the world is rendered, before the screen is refreshed.

    --Use this to perform any 2D drawing you want the entity to display.

    function Script:PostRender(context)

    context:SetBlendMode(Blend.Alpha)

    local pos = self.Cam:GetRotation(true)

    local outText = "Actual angle" .. pos.x .. "|" ..pos.y .."|" ..pos.z

     

    --local outText = self:FaceEntity(self.Cam:GetPosition(true),self.entity:GetPosition(true)).x .."|" ..

    --self:FaceEntity(self.Cam:GetPosition(true),self.entity:GetPosition(true)).y .."|" ..

    --self:FaceEntity(self.Cam:GetPosition(true),self.entity:GetPosition(true)).z

    context:DrawText(outText,0,150)

    context:DrawText("Distance:" .. self:Get3dDistance(self.Cam:GetPosition(true) , self.entity:GetPosition(true)),0,165)

     

     

    pos = self.unitangle

    local outText = "unit angle" .. pos.x .. "|" ..pos.y .."|" ..pos.z

    context:DrawText(outText,0,180)

     

    pos = self.Cam:GetPosition(true)

    local outText = "Cam Position" .. pos.x .. "|" ..pos.y .."|" ..pos.z

    context:DrawText(outText,0,195)

     

    pos = self.entity:GetPosition(true)

    local outText = "Player Position" .. pos.x .. "|" ..pos.y .."|" ..pos.z

    context:DrawText(outText,0,210)

    end

     

     

    --[[

    --This function will be called when the entity is deleted.

    function Script:Detach()

     

    end

    --]]

     

    --[[

    --This function will be called when the last instance of this script is deleted.

    function Script:Cleanup()

     

    end

    --]]

     

×
×
  • Create New...