Jump to content

Genebris

Members
  • Posts

    517
  • Joined

  • Last visited

Posts posted by Genebris

  1. #1 is a design decision. If you would like this to be changed I can consider it.

    I understand that it's more realistic, but there should be a way to work around that. Like another maxacceleration parameter.

     

     

    #2 is diffuicult to judge. How else would this work? What exactly are you describing?

    Have you played Volgarr the Viking? This is what I'm trying to make. In this game you can't control character in the air, but you instantly change speed when using double jump. This includes horizontal and vertical speed. If you are falling down for a few seconds you gain speed, but when you use second jump you instantly get positive vertical speed which wouldn't happen with simple AddForce. Same for horizontal speed.

     

    It's like calling SetVelocity(0,10,0) the first frame user presses a button, but then letting physics engine to calculate everything.

     

     

    I have recorded a short clip to show this

     

     

    Basically, I could use SetVelocity for both, but it doesn't work with character controller. Can you make it work with it?

     

     

    The tradeoffs are inevitable and this is why I coded my own in my last tournament entry. Not to say that there aren't solutions to your problems but I don't know any.

     

    That said, I thought SetVelocity did work on character controllers. I could have sworn I used it to push back enemies in the past when they were hit.

     

    Edit: it was probably AddForce.

    Pretty sure it was AddForce, SetVelocity isn't working for me right now. Did you use rigid body in your game? What did you do with bouncing? I can't launch your game because it starts with too high resolution for my monitor.

  2. I'm making platformer and I have two problems with character controller and SetInput.

     

    1: When walking on the ground movement speed changes instantly, but when in midair it changes very slow. I need my character to instantly change direction while in midair.

     

    2: Jumping applies force instead of instantly changing speed. Again, I need this to be instant.

     

    There wouldn't be problems if SetVelocity worked on character controller, but it doesn't.

     

    I can't use rigid body because it bounces on collisions and there doesn't seem to be a way to disable that.

  3. Material with Z-sort enabled works incorrectly when rendered to a texture. See the screenshot.

    Green and grey materials are regular, blue mat has z-sort enabled. Right part of the image is rendered normally, left part is rendered to a texture and drawn on the context.

     

    post-11962-0-48005100-1481312515_thumb.png

     

    You can see that blue cube on the left is visible through the grey cube. I need to have z-sort enabled for my particles with UV animation, but it makes them visible through the walls.

     

    Script on the camera in this scene:

    
    

    function Script:Start()

    self.tex = Texture:Create(512,512)

    self.cam = Camera:Create()

    self.cam:SetRenderTarget(self.tex)

    end

     

    function Script:PostRender(context)

    context:SetBlendMode(Blend.Alpha)

    context:DrawImage(self.tex,-180,0,512,512)

    end

    • Upvote 1
  4. Jetpack, skiing and shooting with inheritance.

    dl.dropboxusercontent.com/s/an1lrw57r2u1yza/ClansArise.7z

     

     

    Player script

     

    
    

    Script.health = 100

    Script.maxHealth = 100

    Script.mouseSensitivity = 15

    Script.camSmoothing = 2

    Script.moveSpeed = 2.5

    Script.speedMultiplier = 1.5

    Script.strafeSpeed = 4

    Script.playerHeight = 1.8

    Script.eyeheight=0.8

    Script.input={}

    Script.mouseDifference = Vec2(0,0)

    Script.playerMovement = Vec3(0,0,0)

     

    Script.energy=100

     

    --This function will be called when an entity is loaded in a map. Use this for intitial setup stuff.

    function Script:Start()

     

    self.camRotation = self.entity:GetRotation(true)

     

    --create jetpack sound source

    local jetpackSound = Sound:Load("Sound/MSC Nov 16 Sound Effects/Jet Pack Loop 3.wav")

    self.jetpackSource = Source:Create()

    self.jetpackSource:SetSound(jetpackSound)

    self.jetpackSource:SetLoopMode(true)

    self.jetpackSource:SetVolume(0)

    self.jetpackSource:Play()

     

    self.entity:SetPickMode(0) --don't shoot yourself

     

    --Set the type for this object to player

    self.entity:SetKeyValue("type","player")

     

    --Create a camera

    self.camera = Camera:Create()

    self.camera:SetFOV(80)

    self.camera:SetRange(0.05,1000)

    self.camera:SetMultisampleMode((System:GetProperty("multisample","1")))

     

    --Set the camera's rotation to match the player

    self.camera:SetRotation(self.entity:GetRotation(true))

     

    --Set the camera position at eye height

    self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(0,self.eyeheight,0))

     

    --Create listener

    self.listener = Listener:Create(self.camera)

     

     

    ---------------------------------------------------------------------------

    --We want the player model visible in the editor, but invisible in the game

    --We can achieve this by creating a material, setting the blend mode to make

    --it invisible, and applying it to the model.

    ---------------------------------------------------------------------------

    local material = Material:Create()

    material:SetBlendMode(5)--Blend.Invisible

    self.entity:SetMaterial(material)

    material:Release()

    self.entity:SetShadowMode(0)

     

    local window = Window:GetCurrent()

    local context = Context:GetCurrent()

    window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2))

     

    self.disk = self.entity:FindChild("spinfusor"):FindChild("disk")

    self.weapon = Pivot:Create() --detach weapon to move it separately

    self.weapon:SetPosition(self.camera:GetPosition(true),true)

    self.weapon:SetRotation(self.camera:GetRotation(true),true)

    self.entity:FindChild("spinfusor"):SetParent(self.weapon)

     

    self.jetpackParticles = self.entity:FindChild("particles")

    tolua.cast(self.jetpackParticles,"Emitter")

    self.jetpackParticles:Pause()

     

    self.camera:SetRotation(self.camRotation)

     

    self.mainFont=Font:Load("Fonts/arial.ttf",50)

    end

     

     

    function Script:UpdateWorld()

    local window = Window:GetCurrent()

    local context=Context:GetCurrent()

     

    if window:KeyHit(Key.P) then --enable/disable debug view

    if self.debugCameraMode then

    self.camera:SetDebugPhysicsMode(false)

    else

    self.camera:SetDebugPhysicsMode(true)

    end

    self.debugCameraMode=not self.debugCameraMode

    end

     

    --Mouse look

    self.currentMousePos = window:GetMousePosition()

    window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2))

    self.currentMousePos.x = Math:Round(self.currentMousePos.x)

    self.currentMousePos.y = Math:Round(self.currentMousePos.y)

     

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

    self.mouseDifference.x = Math:Curve(self.currentMousePos.x - Math:Round(context:GetWidth()/2),self.mouseDifference.x,3)

    self.mouseDifference.y = Math:Curve(self.currentMousePos.y - Math:Round(context:GetHeight()/2),self.mouseDifference.y,3)

    self.camRotation.x = Math:Clamp(self.camRotation.x + self.mouseDifference.y / self.mouseSensitivity,-90,90)

    self.camRotation.y = self.camRotation.y + (self.mouseDifference.x / self.mouseSensitivity)

     

    --Set the camera angle

    self.camera:SetRotation(self.camRotation)

     

    --position weapon at camera with slight delay

    self.weapon:SetPosition(self.camera:GetPosition(true), true)

    local a = Vec3(0,0,0)

    a.x = Math:CurveAngle(self.camera:GetRotation(true).x, self.weapon:GetRotation(true).x, 2)

    a.y = Math:CurveAngle(self.camera:GetRotation(true).y, self.weapon:GetRotation(true).y, 2)

    a.z = Math:CurveAngle(self.camera:GetRotation(true).z, self.weapon:GetRotation(true).z, 2)

    self.weapon:SetRotation(a, true)

     

     

    if window:MouseHit(1) then

    self:Fire()

    end

     

    if window:KeyHit(Key.R) then

    System:GCSuspend()

    World:GetCurrent():Clear()

    Map:Load("Maps/MSC Nov16.map")

    System:GCResume()

    end

     

    self.disk:SetRotation(self.disk:GetRotation(false)+Vec3(0,15,0),false) --rotate disk inside spinfusor

     

    end

     

     

     

    function Script:UpdatePhysics()

     

    local window = Window:GetCurrent()

     

    --Player Movement

    local movex=0

    local movez=0

    self.input[0]=0

    self.input[1]=0

    if window:KeyDown(Key.W) then self.input[1]=self.input[1]+1 end

    if window:KeyDown(Key.S) then self.input[1]=self.input[1]-1 end

    if window:KeyDown(Key.D) then self.input[0]=self.input[0]+1 end

    if window:KeyDown(Key.A) then self.input[0]=self.input[0]-1 end

     

    local playerMovement = Vec3(0)

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

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

     

    --This prevents "speed hack" strafing due to lazy programming

    if self.input[0]~=0 and self.input[1]~=0 then

    playerMovement = playerMovement * 0.70710678

    end

     

    local velocity=playerMovement*3 --speed that we want to get (if walking)

    local currentSpeed = self.entity:GetVelocity(false)

    currentSpeed.y=0 --we don't want to affect the gravity so we don't include it in calculations

    local extraSpeed = velocity-currentSpeed --speed that we lack

    velocity=velocity+extraSpeed*200 --adding lacking speed

     

    local pickinfo=PickInfo() --check if airborne

    local p1=self.entity:GetPosition(true)

    local onTheGround = World:GetCurrent():Pick(p1,p1-Vec3(0,1,0),pickinfo)

     

    if not window:KeyDown(Key.Space) and onTheGround then --apply walking force only if walking on the ground

    self.entity:AddForce(velocity,false)

    end

     

    if window:KeyDown(Key.Space) then self.entity:SetFriction(0,0) --skiing

    else self.entity:SetFriction(1,1) end

     

    local jetPackActive = false

    if window:MouseDown(2) and self.energy>1 then --jetpack

    local jetpackForce=playerMovement*200

    jetpackForce.y=700

    self.entity:AddForce(jetpackForce, false)

    jetPackActive=true --for sound and particles

    self.energy=self.energy-1

    end

    self.energy=self.energy+0.4

    if self.energy > 100 then self.energy = 100 end

    if self.energy < 0 then self.energy = 0 end

    --end of movement code

     

    --Position camera at correct height and playerPosition

    local playerPos = self.entity:GetPosition()

    local newCameraPos = self.camera:GetPosition()

    --local playerTempHeight = ((self:IsCrouched() == 1) and crouchHeight or playerHeight)

    newCameraPos = Vec3(playerPos.x, newCameraPos.y ,playerPos.z)

     

    if newCameraPos.y<playerPos.y + self.eyeheight then

    newCameraPos.y = Math:Curve(playerPos.y + self.eyeheight, newCameraPos.y, self.camSmoothing)

    else

    newCameraPos.y = playerPos.y + self.eyeheight

    end

     

    self.camera:SetPosition(newCameraPos)

     

    self.entity:PhysicsSetRotation(0,self.camera:GetRotation(true).y,0) --keeping player straight

     

    --jetpack particles and sound

    if jetPackActive then

    self.jetpackParticles:Play()

    self.jetpackSource:SetVolume(self.jetpackSource:GetVolume()+0.2)

    else

    self.jetpackParticles:Pause()

    self.jetpackSource:SetVolume(self.jetpackSource:GetVolume()-0.2)

    end

    if self.jetpackSource:GetVolume()>1 then self.jetpackSource:SetVolume(1) end

    if self.jetpackSource:GetVolume()<0 then self.jetpackSource:SetVolume(0) end

    end

     

     

     

    function Script:Fire()

    local disk = Prefab:Load("Prefabs/Disk.pfb")

    disk:SetPosition(self.camera:GetPosition(true),true)

    disk:SetRotation(self.camera:GetRotation(true),true)

    disk.script.inheritance=self.entity:GetVelocity()/80

    end

     

    function Script:PostRender(context)

    context:SetFont(self.mainFont)

    context:SetBlendMode(Blend.Alpha)

    context:SetColor(1,1,1,1)

     

    context:DrawRect(context:GetWidth()/2-2,context:GetHeight()/2-2,4,4) --crosshair

    local barLength = self.energy*2 --energy bar

    context:DrawRect(context:GetWidth()/2-barLength/2,context:GetHeight()-10,barLength,6)

    if Window:GetCurrent():KeyDown(Key.Space) then --skiing speed

    local speed = Math:Round(self.entity:GetVelocity():Length())..""

    context:DrawText(speed,context:GetWidth()/2-self.mainFont:GetTextWidth(speed)/2, context:GetHeight()-15-self.mainFont:GetHeight())

    end

    end

     

    • Upvote 4
  5. this code does not work

    if window:KeyHit(Key.H) then
    if self.room == "Room1" then ... end
    if self.room == "Room2" then ... end
    if self.room == "Room3" then ... end
    end

    This is the correct way. You check for key exactly one time every update and only then check other conditions. If this is not working then the mistake is in other part of your code which we don't see.

    Maybe you don't check for trigger collision if key isn't hit? Those two checks should be independent.

     

    If you need to flush one key you just get it's state:

    
    

    window:KeyHit(Key.H)

    H key is flushed until next update.

    • Upvote 2
×
×
  • Create New...