Jump to content

fixed camera mode very weird result / bug


Recommended Posts

i am trying to create a thrill camera ( like in stuntman ps2 )

this is the script

server side

thrillcammarker = createColSphere ( -724, 693, -200, 5 ) 
  
function setcam ( element ) 
   setElementPosition ( thrillcammarker, -724, 693, 20 ) 
   outputChatBox ( "1" ) 
end 
  
function thrillcam ( element ) 
   triggerClientEvent ( element, "onchangeCamera", getRootElement () ) 
   setTimer ( setElementPosition, 1000, 1, thrillcammarker, -724, 693, -200 ) 
   setGameSpeed ( 0.3 ) 
   setTimer ( setGameSpeed, 3000, 1, 1.0 ) 
   outputChatBox ( "2" ) 
end 
  
addCommandHandler ( "startcamera", setcam ) 
addEventHandler ( "onColShapeHit", thrillcammarker, thrillcam ) 

client side

local root = getRootElement() 
local localPlayer = getLocalPlayer () 
local update = false 
  
function updateCameraPos() 
   local x, y, z = getElementPosition ( localPlayer ) 
   setCameraLookAt ( x, y, z ) 
    
end 
   
   
function changeCamera() 
   if ( update == false ) then 
     update = true 
     toggleCameraFixedMode ( true ) 
     setCameraPosition ( -681, 662, 18 ) 
     addEventHandler ( "onClientRender", root, updateCameraPos ) 
     setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
   else 
     update = false 
     toggleCameraFixedMode ( false ) 
     removeEventHandler ( "onClientRender", root, updateCameraPos ) 
   end 
end 
   
addEvent ( "onchangeCamera", true ) 
addEventHandler ( "onchangeCamera", getRootElement (), changeCamera ) 

and here are some screenshots to help explain

http://www.fileshack.us/get_file.php?id=377157&file=mta-screen0040.png

the collision sphere that changes camera and sets game speed is at the top of the ramp

http://www.fileshack.us/get_file.php?id=529932&file=mta-screen0041.png

this is where u land after the jump and is safe to drive on but if u go a little further down the road this happens

http://www.fileshack.us/get_file.php?id=257015&file=mta-screen0050.png

u just fall straight through like there is no road. this only happens after you have hit the collision sphere and the camera is moved and put back on the player. if i just type the command startcamera but dont hit the collision sphere every thing is fine.

i have tried driving cars and bikes and planes and even the jetpack but everything falls through the ground and trees and buildings are no longer solid either.

i havent tested the whole map but it seems everything beyond where i set the camera is gone and everything before where i set the camera is ok ( even the water )

i think this is a really cool script and the results ( when they work ) are pretty neat. another issue i have with this is that the camera change only works every other time you use it. if i join the game and type startcamera then hit collision sphere it puts the camera in a totally different place ( the farm i think ) and the second time it works properly but the third time game slows down i get chatbox message "1" but no camera change but the fourth time it works perfect and from there on it works every other time. i have tried to test it as much as i could but i dont know what else to try. i can live with it not working perfect every time but the non solid world is a major problem LOL

any help / ideas really appreciated thanx :D:D

Link to comment

[..]

any help / ideas really appreciated thanx :D:D

All I can say is that the camera function is buggy in DP2. Multiple people have reported camera issues when you join a server for the first time. Sometimes setting the camera works and when it doesn't the camera seems to be stuck at 0,0,0 (that is indeed at the farm). Also note that you can not set the camera position and look at target in the same frame.

The part where you fall through the "world" is almost certainly related to the instability of the camera functions. Somehow setting the camera in the client render event while the camera is still in fixed mode can trigger fatal bugs to the MTA streamer.

In short, don't set the camera position or look at target when the camera is in fixed mode. This causes instabilities like objects disappearing and falling through the "world".

Link to comment

thanx for the reply ACE_GAMBIT

i have just tried it without the onClientRender and it works but the camera doesnt look at the player.

on the wiki there are two rotate camera functions ( thought that might work better than setCameraLookAt ) but when i try to view them it says this

The action you have requested is limited to users in the group user.

does this mean i cant use it or is there just no example yet.

i was also looking at setCameraTarget but it looks like that would just follow the player as normal ( and id need extra player )

is there any way around this ( possibly in DP3 / maybe even PED CAMs )

forgot to put the script in LOL

client side

local root = getRootElement() 
local localPlayer = getLocalPlayer () 
local update = false 
   
   
function changeCamera() 
   local x, y, z = getElementPosition ( localPlayer ) 
   if ( update == false ) then 
     update = true 
     toggleCameraFixedMode ( true ) 
     setCameraPosition ( -681, 662, 18 ) 
     setCameraLookAt ( x, y, z ) 
     setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
   else 
     update = false 
     toggleCameraFixedMode ( false ) 
   end 
end 
   
addEvent ( "onchangeCamera", true ) 
addEventHandler ( "onchangeCamera", getRootElement (), changeCamera ) 

i have also tried putting a timer on setCameraLookAt ( 1 tenth of a second ) just to see if it didnt like me trying to setCameraPosition and setCameraLookAt at the same time but no difference

EDIT ::: i just tried using rotateCameraRight but it doesnt have an example on the wiki so im not sure if i have syntax right

does anyone know how to use rotateCamereaRight and rotateCameraUp.

Link to comment

This was as close as I could get:

  
function camTrack() 
    setCameraLookAt(getElementPosition(getLocalPlayer())) 
end 
  
function camTrackOn() 
    addEventHandler("onClientRender",getLocalPlayer(),camTrack) 
end 
  
function camTrackOff() 
    removeEventHandler("onClientRender",getLocalPlayer(),camTrack) 
end 
  
function camTrackStart(duration) 
    local x,y,z = getElementPosition(getLocalPlayer()) 
  
    toggleCameraFixedMode(false) 
    toggleCameraFixedMode(true) 
  
    setTimer(setCameraPosition,50,1,x + 30,y + 30,z + 10) 
  
    setTimer(camTrackOn,100,1) 
    setTimer(camTrackOff,duration - 100,1) 
  
    setTimer(toggleCameraFixedMode,duration,1,false) 
end 
  
addCommandHandler("camtest",         
    function() 
        camTrackStart(15000) 
    end  
) 
  

I've just butchered your code to make this but it does put the camera away from the player and then specs them for 15 seconds (use /camtest).

It's a little jerky (in a fast vehicle) but maybe that will be helped in DP3 with onClientPreRender or the new camera functions.

Link to comment

No problem. I've spent a while trying various camera calls (server/client side, on timers etc.) and the above sequence was the one I found most reliable. The camera dropping through the world is a distance-based issue - changing the camera mode from/to fixed when the camera position is far away from the player. I worked out a fixed for that but it involves move the players position as well as the camera. In your stunt mode you should be able to drop the time from 15 seconds down to whatever you won't so this shouldn't happen too often.

Link to comment

Take a look into my modshop resource and you will see that you can set "camera position" and "camera look at" in the same frame. In the file gui.lua you'll find a function rotateCameraAroundPlayer (which is at the bottom of the file). That function is called every frame when you are tuning your vehicle. Also look at lines 75, 76.

Link to comment

the camera is working great now ( thank u so much guys )

the falling through the world thing isnt a problem now ( turned the time down to 5 seconds ) it still happens but the way im using it the camera resets before you get to the point where u fall through the world ( awesome :D )

i am now trying to display a text message on screen when the camera change is triggered but i cant get it workin.

i have written an extra function just to see if i could get the text workin and i was going to add it to the camera change function later. here is what ive got so far

server code only

function sayit ( player ) 
   thebox = textCreateDisplay () 
   inthebox = textCreateTextItem ( "YEEeee  HAAAwwww!!", 0.5, 0.5, 2, 255, 0, 0, 1.0, center, center ) 
   textDisplayAddObserver ( thebox, player ) 
   textDisplayAddText ( thebox, inthebox ) 
   setTimer ( textDestroyDisplay, 3000, 1, thebox ) 
end 
  
addCommandHandler( "saysomething", sayit ) 

it doesnt give me any errors but no text either. i have been looking through the forums ( theres loads of threads about text ) but i cant find one about just displaying a simple message to screen. all i want it to do is say "YEEeee HAAAwwww!!" in middle of screen and then disappear after 3 seconds. i am going to trigger it at the same time as the camera change so when you do the jump game slows down / camera changes / it prints YEEeee HAAAwwww!! as your jumping / then camera returns and game speeds up .

i did notice this in another thread but i dont know if this is what im missing. not sure about the setElementData part ( do i need it ) because there is no mention of it in the wiki example.

I have a annoying problem with setting element data like in text displays tutorial http://www.multitheftauto.com/tutorial5.html (Setting up dynamic displays)

Line number On/Off | Expand/Contract | Select all

1. local myTextDisplay = textCreateDisplay () -- create a text display

2. local myTextItem = textCreateTextItem( "", 0.7, 0.7) -- create a text item for the display

3. textDisplayAddText ( myTextDisplay, myTextItem ) -- add it to the display so it is displayed

4. setElementData ( source, "textItem_myTextItem", myTextItem ) -- <-- problem

5. textDisplayAddObserver ( myTextDisplay, source )

When it tries to setelementdata it prints to console "Couldn't packetsize argument list, invalid element speciefed." , it sets it correctly, but the error..

Can it be fixed somehow, that this error wouldn't show up

as always any help appreciated

Link to comment

1. Try to add the textItem to textDisplay before you show it to the player, so just move it aboute textDisplayAddObserver

2. setElementData is used to synch variables so you can use it in client-side script. You can't synch textItem because it's server-side only.

Link to comment

thanx 50P

i just tried it like this but same result

function sayit ( player ) 
   inthebox = textCreateTextItem ( "YEEeee HAAAwwww!!", 0.5, 0.5, 2, 255, 0, 0, 1.0, center, center ) 
   thebox = textCreateDisplay () 
   textDisplayAddText ( thebox, inthebox ) 
   textDisplayAddObserver ( thebox, player ) 
   setTimer ( textDestroyDisplay, 3000, 1, thebox ) 
end 
  
addCommandHandler( "saysomething", sayit ) 

i have been looking at a number of resources ( deathmessages / killmessages / stunt ) and they all seem to create the text display when the player joins or resource starts and then use a ( field or array not sure what its called ) to fill in the text. would i be better off trying it like that. oh well ill give it a go and see what happens :D

EDIT:::

managed to get this working

thebox = textCreateDisplay () 
inthebox = textCreateTextItem ( "YEEeee HAAAwwww!!", .5, .5, "low", 255, 0, 0, 255, 1.0, "center" ) 
  

function sayit ( player ) 
   textDisplayAddText ( thebox, inthebox ) 
   textDisplayAddObserver ( thebox, player ) 
   setTimer ( textDestroyDisplay, 3000, 1, thebox ) 
end 
  
addCommandHandler( "saysomething", sayit ) 

text is quite small though so if anyone wants to use it u will probably want to make it bigger ( im about to do so myself ) :D

EDIT 2:::::

and at last the fully working THRILLCAM

screenshots

http://www.fileshack.us/get_file.php?id=900341&file=mta-screen0003.png

http://www.fileshack.us/get_file.php?id=986821&file=mta-screen0004.png

http://www.fileshack.us/get_file.php?id=523180&file=mta-screen0005.png

and script

server side

thrillcammarker = createColSphere ( -724, 693, -200, 5 ) 
local root = getRootElement() 
local thebox = textCreateDisplay () 
inthebox = textCreateTextItem ( "YEEeee HAAAwwww!!", .5, .5, "low", 255, 0, 0, 150, 4.0, "center" ) 
  
  
function setcam ( element ) 
   setElementPosition ( thrillcammarker, -724, 693, 20 ) 
   outputChatBox ( "1" ) 
end 
  
function thrillcam ( player ) 
   triggerClientEvent ( player, "oncamtest", getRootElement () ) 
   setTimer ( setElementPosition, 1000, 1, thrillcammarker, -724, 693, -200 ) 
   textDisplayAddText ( thebox, inthebox ) 
   textDisplayAddObserver ( thebox, player ) 
   setTimer ( textDisplayRemoveObserver, 3000, 1, thebox, player ) 
   setGameSpeed ( 0.3 ) 
   setTimer ( setGameSpeed, 4000, 1, 1.0 ) 
   outputChatBox ( "2" ) 
end 
  
addEventHandler ( "onColShapeHit", thrillcammarker, thrillcam ) 
addCommandHandler ( "startcamera", setcam ) 

client side

local root = getRootElement() 
local localPlayer = getLocalPlayer () 
local update = false 
   
   
  
 function camTrack() 
     setCameraLookAt(getElementPosition(getLocalPlayer())) 
 end 
   
 function camTrackOn() 
     addEventHandler("onClientRender",getLocalPlayer(),camTrack) 
 end 
   
 function camTrackOff() 
     removeEventHandler("onClientRender",getLocalPlayer(),camTrack) 
 end 
   
 function camTrackStart(duration) 
     local x,y,z = getElementPosition(getLocalPlayer()) 
   
     toggleCameraFixedMode(false) 
     toggleCameraFixedMode(true) 
   
     setTimer(setCameraPosition, 50, 1, -717, 710, 20 ) 
   
     setTimer(camTrackOn,100,1) 
     setTimer(camTrackOff,duration - 100,1) 
   
     setTimer(toggleCameraFixedMode,duration,1,false) 
 end 
  
      function camteset() 
         camTrackStart(5000) 
     end  
 addEvent ( "oncamtest", true ) 
 addEventHandler ( "oncamtest", getLocalPlayer(), camteset ) 

with debugscript 3 on i get no errors so it should be ok to run for everyone :D

forgot to add the ramp

put this line in your map file

<object model="16303" posX="-740.47650146484" posY="700.71752929688" posZ="13.409936904907" rotX="359.5" rotY="0" rotZ="350"/> 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...