Slastraf Posted February 24, 2015 Share Posted February 24, 2015 Hello I was making an UFO camera attached to a model which is attached to an modified fps player. the fps player model does not rotate.(neither anything) So : my problem is that i cant make the PlayerModel facing the direction it walks, i already tried keydown : a, etc. -> setrotation (does not work for me, only in x axis in all 3 variables that it needs) and some other things that are not necessary So anyone got a solve? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 24, 2015 Share Posted February 24, 2015 Use the SetInput() function to rotate the player to the direction you want. First parameter is the Y axis. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitysetinput-r706 Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 Use the SetInput() function to rotate the player to the direction you want. First parameter is the Y axis. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/entitysetinput-r706 so now i tried in updatephysics: if App.window:KeyDown(Key.A) then self.entity:SetInput(45,0 ,0) end (45 only for test) no reaction, no error Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 24, 2015 Share Posted February 24, 2015 Can you post your fps script? Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 RpgMovement script: (modified fps script) import "Scripts/Functions/ReleaseTableObjects.lua" Script.health = 100 --float "Health" Script.maxHealth = 100 --float "Max Health" Script.mouseSensitivity = 15 --float "Mouse sensitivity" Script.camSmoothing = 2 --float "Cam smoothing" Script.moveSpeed = 2.5 --float "Move Speed" Script.speedMultiplier = 1.5 --float "Run Multiplier" Script.strafeSpeed = 4 --float "Strafe Speed" Script.playerHeight = 1.8 --float "Player Height" Script.jumpForce = 8 --float "Jump Force" Script.useDistance = 2 Script.alive=true Script.eyeheight=1.6 Script.footstepwalkdelay = 500 Script.footsteprundelay = 300 Script.weaponfile=""--path "Weapon" "Prefab (*.pfb):pfb|Prefabs" Script.input={} Script.maxcarryweight=5 Script.throwforce = 500 Script.isairborne=false Script.bloodindex=1 Script.teamid=1--choice "Team" "Neutral,Good,Bad" Script.hurtoffset=Vec3(0) Script.smoothedhurtoffset=Vec3(0) Script.mouseDifference = Vec2(0,0) Script.playerMovement = Vec3(0,0,0) Script.tempJumpForce = 0 --This function will be called when an entity is loaded in a map. Use this for intitial setup stuff. function Script:Start() self.currentweaponindex=-1 self.camRotation = self.entity:GetRotation(true) self.weaponlowerangle=0 self.image={} self.image.crosshair = Texture:Load("Materials/HUD/crosshair.tex") self.image.hand = Texture:Load("Materials/HUD/use.tex") self.image.blood={} self.image.blood[1]=Texture:Load("Materials/HUD/blood1.tex") self.image.blood[2]=Texture:Load("Materials/HUD/blood2.tex") self.image.blood[3]=Texture:Load("Materials/HUD/blood3.tex") self.image.blood[4]=Texture:Load("Materials/HUD/blood4.tex") --Load shared sounds self.sound={}--table to store sound in self.sound.damage={} self.sound.damage[1]=Sound:Load("Sound/Impact/body_punch_03.wav") self.sound.damage[2]=Sound:Load("Sound/Impact/body_punch_04.wav") self.sound.pickupweapon=Sound:Load("Sound/Player/pickupammo.wav") self.sound.footsteps={} self.sound.footsteps.concrete={} self.sound.footsteps.concrete.step={} self.sound.footsteps.concrete.step[1] = Sound:Load("Sound/Footsteps/Concrete/step1.wav") self.sound.footsteps.concrete.step[2] = Sound:Load("Sound/Footsteps/Concrete/step2.wav") self.sound.footsteps.concrete.step[3] = Sound:Load("Sound/Footsteps/Concrete/step3.wav") self.sound.footsteps.concrete.step[4] = Sound:Load("Sound/Footsteps/Concrete/step4.wav") self.sound.footsteps.concrete.jump = Sound:Load("Sound/Footsteps/Concrete/jump.wav") self.bloodoverlay={} self.entity:SetPickMode(0) --Set the type for this object to player self.entity:SetKeyValue("type","player") local mass = self.entity:GetMass() if self.entity:GetMass()==0 then Debug:Error("Player mass should be greater than 0.") end --Create a camera self.camera = Camera:Create() self.camera:SetFOV(70) self.camera:SetRange(0,0) 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) local window = Window:GetCurrent() local context = Context:GetCurrent() window:SetMousePosition(Math:Round(context:GetWidth()/2), Math:Round(context:GetHeight()/2)) self.camera:SetRotation(self.camRotation) if self.weaponfile~="" then local prefab = Prefab:Load(self.weaponfile) if prefab~=nil then if prefab.script~=nil then self:AddWeapon(prefab.script) else prefab:Release() end end end local material = Material:Create() material:SetBlendMode(5)--Blend.Invisible self.entity:SetMaterial(material) material:Release() self.entity:SetShadowMode(0) end function Script:Release() self.listener:Release() if self.corpse~=nil then self.corpse:Release() self.corpse=nil end ReleaseTableObjects(self.sound) ReleaseTableObjects(self.image) local k,v for k,v in pairs(self.weapons) do v:Release() end end function Script:Collision(entity,position,normal,speed) if speed>20 then self:Hurt(100) end end function Script:Hurt(damage,distributorOfPain) if self.health>0 then self.sound.damage[math.random(#self.sound.damage)]:Play() self.health = self.health - damage self.hurtoffset = Vec3(math.random(-1,1),math.random(-1,1),0):Normalize()*30 local blood = {} local n=1 blood.texture=self.image.blood[math.random(1,4)] blood.intensity=1 table.insert(self.bloodoverlay,blood) if self.bloodindex>4 then self.bloodindex=1 end if self.health<=0 then self:Kill() end end end function Script:Kill() self.corpse = Pivot:Create() local shape = Shape:Load("Models/Characters/Generic/corpse.phy")--this shape is made from a low-poly CSG sphere, so it will roll around a bit but come to a stop quickly self.corpse:SetShape(shape) if shape~=nil then shape:Release() end self.corpse:SetMass(5) self.corpse:SetMatrix(self.camera:GetMatrix()) self.camera:SetParent(self.corpse) self.camera:SetPosition(0,0,0) self.camera:SetRotation(0,0,0) self.corpse:SetCollisionType(Collision.Prop) self.corpse:SetSweptCollisionMode(true) self.entity:SetCollisionType(0) self.corpse:SetFriction(10,10) local maxomega=5 self.corpse:SetOmega(Vec3(math.random(-maxomega,maxomega),math.random(-maxomega,maxomega),math.random(-maxomega,maxomega))) local v = self.entity:GetVelocity() if v:Length()>1 then v=v:Normalize() end self.corpse:SetVelocity(Vec3(math.random(-1,1),math.random(-1,1),math.random(-1,1))) self.entity:SetMass(0) self.entity:SetPhysicsMode(Entity.RigidBodyPhysics) end function Script:FindUsableEntity(entity) while entity~=nil do if entity.script then if type(entity.script.Use)=="function" then --If "enable" has not been set, it still won't be "false" so this will pass: if entity.script.enabled~=false then return entity else return nil end end end entity = entity:GetParent() end return nil end function Script:UpdateWorld() local currenttime = Time:GetCurrent() --Exit the function early if the player is dead if self.health<=0 then return end local window = Window:GetCurrent() local context=Context:GetCurrent() if window:KeyHit(Key.P) then self.camera:SetDebugPhysicsMode(true) end self.isairborne = self.entity:GetAirborne() end --This function plays footstep sounds in regular intervals as the player walks function Script:UpdateFootsteps() if self.lastfootsteptime==nil then self.lastfootsteptime=0 end if self.input[0]~=0 or self.input[1]~=0 then local speed = self.entity:GetVelocity():xz():Length() if self.entity:GetAirborne()==false then if (speed>self.moveSpeed*0.5) then local t = Time:GetCurrent() local repeatdelay = self.footstepwalkdelay if speed>self.moveSpeed * (1+(self.speedMultiplier-1)*0.5) then repeatdelay = self.footsteprundelay end if t-self.lastfootsteptime>repeatdelay then self.lastfootsteptime = t local index = math.random(1,4) self.sound.footsteps.concrete.step[index]:Play() end end end end end --This function will be called once per physics update function Script:UpdatePhysics() if self.health<=0 then return end local window = Window:GetCurrent() --Fade out the screen blood if self.bloodintensity~=nil then if self.bloodintensity>0 then self.bloodintensity = self.bloodintensity-0.01 self.bloodintensity = math.max(0,self.bloodintensity) end end --Update the footstep sounds when walking self:UpdateFootsteps() --Toggle the flash light on and off --Apply forces to make the carried object move the way we want if self.carryingEntity then local currentpos = self.carryingEntity:GetPosition(true) local pos = Transform:Point(self.carryposition,self.camera,nil) local rot = Transform:Rotation(self.carryrotation,self.camera,nil) local maxdiff = 0.5 local diff = pos:DistanceToPoint(currentpos) --Drop the carryinItem when the distance between camera and item exceed the pickdistance if diff>1.5 then self:DropEntityCarrying() else if diff>maxdiff then pos = currentpos + (pos-currentpos):Normalize()*maxdiff diff = maxdiff end self.carryingEntity:PhysicsSetPosition(pos.x,pos.y,pos.z,0.25) self.carryingEntity:PhysicsSetRotation(rot,0.5) end end --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 --if self.entity:GetAirborne() then -- playerMovement = playerMovement * 0.2 --end --Check for running with shift and when not carrying anything if self.carryingEntity == nil and window:KeyDown(Key.Shift) then playerMovement.z = playerMovement.z * self.speedMultiplier end -- Check for jumping local jump = 0 if window:KeyHit(Key.Space) and self:IsAirborne() == 0 then jump = self.jumpForce self.sound.footsteps.concrete.jump:Play() --Give the player an extra boost when jumping playerMovement = playerMovement * 1.6 end -- Check for crouching --if App.window:KeyHit(Key.ControlKey) then -- crouched = not crouched --end --With smoothing --Position camera at correct height and playerPosition self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true) 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) end --Return whether the player is airborne function Script:IsAirborne() return self.entity:GetAirborne() and 1 or 0 end function Script:PostRender(context) --TakeDamage end function Script:TakeDamage(damage) --Decrease health self.health = self.health - damage; --Call OnHit output self:OnHit() --If health lower or equal to zero, the player is dead if self.health <= 0 then self.alive = false --Call the OnDead output self:OnDead() end end --Increase health function Script:ReceiveHealth(healthPoints)--in --Increase health self.health = self.health + healthPoints; --Health can not be more then maximum health if self.health > self.maxHealth then self.health = self.maxHealth end --Call Health received output self.component:CallOutputs("HealthReceived") end --when health is zero or lower, an output call is made function Script:OnDead()--out --Extra check to make sure that the player is no longer alive if not(self:IsAlive()) then self.component:CallOutputs("Ondead") end end --when the player gets damaged we call this output function Script:OnHit()--out self.component:CallOutputs("OnHit") end RPG_modeltoplayer script: function Script:Start() end function Script:UpdateWorld() end function Script:UpdatePhysics() if App.window:KeyDown(Key.A) then self.entity:SetInput(45,0 ,0) end end function Script:Draw() end function Script:Render() self.entity:SetPosition(self.pivot:GetPosition(true),true) end sorry for length, better you make this in a empty script for overview Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 24, 2015 Share Posted February 24, 2015 You are using the SetInput in both the UpdateWorld and the UpdatePhysics. Try commenting out the one in UpdateWorld. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 i tried both; only updateworld and only updatephysics; no reaction or what do you want to say with commenting out in updateworld Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 24, 2015 Share Posted February 24, 2015 Okay to clarify, this is your hierarchy: FPSplayer (with modified FPSplayerscript, Character controller, Character Collision Type)Model (no script, not a character controller) If you have a script on your model as well, then this will conflict with the FPS player script attached to the parent. Can you otherwise send a screenshot of your hierachy. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 Player with fpsplayersript modified and other things I have Camera with thirdpersonfollow as target player, PlayerModel attached to player with modeltoplayerscript all physics are same as you said player -> ccharcontroller, collision : char playermodel-> rigid body, no shape, no collision type camera aswell" tried to put if App.window:KeyDown(Key.A) then self.entity:SetInput(45,0 ,0) end in modified fpsplayer, nothing still happens even modeltoplayer has no script Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 24, 2015 Share Posted February 24, 2015 I have no idea how this looks in your scene, can you give us a screenshot of your hierarchy. If you have multiple scripts for the player which both to self.entity:SetInput() things will start to go wrong. If you create a camera in the scene, you need to link it to the FPS player, since that script creates a camera via script. That means you have double camera's. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 I have already deleted the camera in the fpsscript, also didnt got a probelm with that for now http://www.artur-betz.de/lel here is the link for image i got bugs with leadwerks site discovered sry for link was the fastest way i could make Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted February 24, 2015 Share Posted February 24, 2015 Thanks, Okay try the following: The PlayerModel and Camera have no scripts. The Player has a script attached Script.rotateSpeed = 1.0 --float "Rotatespeed"function Script:UpdatePhysics() if App.window:KeyDown(Key.A) then self.entity:SetInput(Time:GetSpeed() * self.rotateSpeed ,0 ,0) endend [*]Adjust rotation value if needed. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 still no affect. this makes no bugs, nothing has a script attached except player *frustrating* , got options (anyone ? Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 do you got teamviewer so you can look at this yourself ? Quote Link to comment Share on other sites More sharing options...
shadmar Posted February 24, 2015 Share Posted February 24, 2015 I was thinking (haven't tried, but you could): self.dir=player:GetVelocity():Normalized() model:AlignToVector(self.dir) Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 I put self.dir = self.GetVelocity():Normalized() self.entity:AlignToVector(self.dir) in updatephysics() .it gives me the error attemt to call field getvelocity (a nil value) dont know why this happens, am i missing something ? Quote Link to comment Share on other sites More sharing options...
Josh Posted February 24, 2015 Share Posted February 24, 2015 self.entity:GetVelocity():Normalize() Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted February 24, 2015 Author Share Posted February 24, 2015 think i should go on bug report with setrotation() seems like it safes the first input, then always returns this value even if u put in new ones Quote Link to comment Share on other sites More sharing options...
Dralel Posted December 29, 2015 Share Posted December 29, 2015 Bump, having the exact same issue that it only does the SetInput command once. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted December 30, 2015 Share Posted December 30, 2015 Got tricked by your bump. I thought Aggror was back Quote Link to comment Share on other sites More sharing options...
Slastraf Posted December 30, 2015 Author Share Posted December 30, 2015 I remember I solved it by just setting the rotation on the wasd keys. Doesnt look realistic but its a quick solve. Quote Link to comment Share on other sites More sharing options...
Dralel Posted December 31, 2015 Share Posted December 31, 2015 I tried that, but it doesn't work if the entity is set to character controller physics and has a mass greater than 0. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted December 31, 2015 Author Share Posted December 31, 2015 Also you could make the player going somewhere by right click, just make a pick from the ufo camera which places a pivot at the pick position and use GoToPoint(pivot:GetPos) on this player. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted January 2, 2016 Author Share Posted January 2, 2016 I have programmed the above for my needs. If interested i will post the script Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.