Jump to content

Concern about camera?


Yue
 Share

Go to solution Solved by tipforeveryone,

Recommended Posts

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.
image.png.5f6d1e7d82f5eb0bc675dcf7392d4bb4.png


Camera in position in point Collision with a wall

image.png.9aee839ab19ced03b06daa91dcf37065.png

 

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

 

 

 

Link to comment
Share on other sites

  • Solution

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 :D

image.png.f2abfb15507bd33047188a891acc8494.png

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

I'm telling you, I did this. 

:)

 

image.png.92074030af8dad8df6ae1c732c36f36f.png

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

 

 

  • Like 1

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...