Yue Posted June 16, 2018 Share Posted June 16, 2018 I have a camera that follows a character from a distance. When the camera collides with a wall using a beam, it is positioned at the point of collision, however after that collision, I need the camera to be reset to its initial position. Any suggestions? Camera in original position when following the player. Camera in position in point Collision with a wall The idea is that after the collision, it will return to its original point smoothly. I welcome any suggestions. function Script:UpdateWorld() local pickinfo = PickInfo() -- Giro Camara GiroCamara(self) -- Colision Camara posCamara = self.Camara:GetPosition(true) posPivote= self.entity:GetPosition(true) if world:Pick( posPivote.x, posPivote.y, posPivote.z, posCamara.x, posCamara.y, posCamara.z, pickinfo , 0, false ) then System:Print("Col OK") self.Camara:SetPosition( pickinfo.position, true ) else --self.Camara:Move(0, 1, 0, true ) System:Print( "Col Not") end end Quote Link to comment Share on other sites More sharing options...
Solution tipforeveryone Posted June 17, 2018 Solution Share Posted June 17, 2018 I use this for my weapon blocking (by wall) system, I think it will work with your camera You can calculate the distance between the pickInfo.position and the entity which you put start of Pick (Beam Point 1) then use the maximum range of your camera to player (self.defaultCameraRange) minus that, you get the distance between MaxRange to pickInfo.position (called self.collisionMinusRange) Because camera point its Z axis to player, so that you can use entity:Move(0,0,self.collisionMinusRange) In the meantime, Use camera:SetPosition(self.beamPoint2:GetPosition(true)) to keep you camera at the maxRange when not collided any obstacle Hope you can understand what I am trying to explain 1 2 Quote Link to comment Share on other sites More sharing options...
Yue Posted June 17, 2018 Author Share Posted June 17, 2018 I'm telling you, I did this. Script.Camara = nil --entity "Camara" Script.Yue = nil --entity "Yue" Script.PivoteCamara = nil --entity "Pivote Camara" Script.Escenario = nil --entity "Escenario" posCamara = Vec3() posPivotePlayer = Vec3() posPivoteCamara = Vec3() function Script:Start() self.Camara:SetRange(0.01, 100) self.Escenario:SetPickMode( Entity.PolygonPick ) self.entity:SetPickMode(0) self.Yue:SetPickMode( 0 ) end function Script:UpdateWorld() local pickinfo = PickInfo() -- Giro Camara GiroCamara(self) -- Colision Camara posCamara = self.Camara:GetPosition(true) posPivotePlayer = self.entity:GetPosition(true) posPivoteCamara = self.PivoteCamara:GetPosition(true) if world:Pick( posPivotePlayer.x, posPivotePlayer.y, posPivotePlayer.z, posPivoteCamara.x, posPivoteCamara.y, posPivoteCamara.z, pickinfo , 0.11, true ) then System:Print("Col OK") self.Camara:SetPosition( pickinfo.position, true ) else --self.Camara:Move(0, 1, 0, true ) System:Print( "Col Not") self.Camara:SetPosition( posPivoteCamara, true ) end --self.Yue:GoToPoint(0, 100, 0 ) end pivote = Vec3() -- Giro Camara libre function GiroCamara(self) --Get the mouse movement local sx = Math:Round(context:GetWidth()/2) local sy = Math:Round(context:GetHeight()/2) local mouseposition = window:GetMousePosition() local dx = mouseposition.x - sx local dy = mouseposition.y - sy --Adjust and set the camera rotation pivote.x = pivote.x + dy / 10.0 pivote.y = pivote.y + dx / 10.0 self.entity:SetRotation(pivote) --Move the mouse to the center of the screen window:SetMousePosition(sx,sy) if pivote.x >= 45 then pivote.x = 45 elseif pivote.x <= -45 then pivote.x = -45 end end 1 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted June 17, 2018 Share Posted June 17, 2018 Does your camera have a script? I got this from Aggror's death trigger script. Maybe put this on your camara? You'd have to create a pivot and child the pivot where the camera will reset to the player too. Script.start = "" --entity "Start Point" function Script:Collision(entity, position, normal, speed) reset = self.start:GetPosition() self.entity:SetPosition(reset) end Quote Link to comment Share on other sites More sharing options...
Yue Posted June 17, 2018 Author Share Posted June 17, 2018 1 hour ago, havenphillip said: Does your camera have a script? I got this from Aggror's death trigger script. Maybe put this on your camara? You'd have to create a pivot and child the pivot where the camera will reset to the player too. Script.start = "" --entity "Start Point" function Script:Collision(entity, position, normal, speed) reset = self.start:GetPosition() self.entity:SetPosition(reset) end No, I'm telling you what I did and how I put it on the development blog. It is a lightning bolt that comes out of a pivot that is close to the player's neck and if its target is another pivot that is at a certain distance from the character, then the camera is hooked to that second pivot. When the beam collides with a wall, the camera is positioned at the point of collision and when the beam does not collide with anything, it is positioned at the second pivot position. I'm thinking that you can use ToGoPoint, so that the camera moves at a smooth speed and doesn't jump to the second pivot with a single movement. Translated with www.DeepL.com/Translator Quote Link to comment Share on other sites More sharing options...
havenphillip Posted June 17, 2018 Share Posted June 17, 2018 Oops. My mistake. 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.