# Pickups

## Recommended Posts

Hey,

I am making my own gamemode and how can I make it so when I enter it the player's Z rotation goes 0 but only if the player is in air and isn't touching any objects. What I want is similar behaviour to the default race gamemod's pickups.

I really don't understand you

Ok sry,

What I mean is when you play DM with race gamemode and you have sidewall you immediately jump and there is a vehicle change pick up you change rotation so the car is straight.

But when you would be on sidewall your rotation will not be changed.

What I wanna do is to check if a player is driving on an object or is in air

I know what you do mean, you must look at race's client code and check how the pickups work. You can start by looking at the code following to the line nº1352 ("Make vehicle upright") at the race_client.lua file; which must be like the following:

```
------------------------
-- Make vehicle upright

function directionToRotation2D( x, y )
return rem( math.atan2( y, x ) * (360/6.28) - 90, 360 )
end

function alignVehicleWithUp()
local vehicle = g_Vehicle
if not vehicle then return end

local matrix = getElementMatrix( vehicle )
local Right = Vector3D:new( matrix[1][1], matrix[1][2], matrix[1][3] )
local Fwd   = Vector3D:new( matrix[2][1], matrix[2][2], matrix[2][3] )
local Up    = Vector3D:new( matrix[3][1], matrix[3][2], matrix[3][3] )

local Velocity = Vector3D:new( getElementVelocity( vehicle ) )
local rz

if Velocity:Length() > 0.05 and Up.z < 0.001 then
-- If velocity is valid, and we are upside down, use it to determine rotation
rz = directionToRotation2D( Velocity.x, Velocity.y )
else
-- Otherwise use facing direction to determine rotation
rz = directionToRotation2D( Fwd.x, Fwd.y )
end

setElementRotation( vehicle, 0, 0, rz )
end

```

## Create an account

Register a new account