xTravax Posted August 1, 2015 Share Posted August 1, 2015 hey guys how could i always flip a car in front direction? i mean look like here car is currently in certain rotation while at wallride, and when it hits the pickup it gets correct, and front direction rotation how could i achieve this front direction thing nevertheless of the vehicle state(whether its on roof, half on roof or not on roof at all) ? In race code it uses some vectors and/or element/camera matrix to calculate this, but i don't really understand it.. Thanks in advance Link to comment
Noki Posted August 1, 2015 Share Posted August 1, 2015 getElementRotation, then just use setElementRotation to set the rotation. Link to comment
LabiVila Posted August 1, 2015 Share Posted August 1, 2015 Just to let you know, if you're doing a race server, the race pickup automatically turns your car as you're actually wanting Link to comment
xTravax Posted August 1, 2015 Author Share Posted August 1, 2015 Labivilla i'm using my own race. @Noki that rotation thing works sometimes and sometimes doesn't. The vehicle doesn't get front directioned and 'flipped' like in the video, that's probably because setElementRotation works in some cases, and in some not, and maybe that's why race uses matrices/vectors, but i don't know how to do those. also, the thing is that if car is in air, and currently rotated like it's on roof, it should rotate the vehicle to front and not on roof normally, but i dont' know how to achieve that. edit: i believe this is how it's done in race but i don't understand it 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 Link to comment
GTX Posted August 1, 2015 Share Posted August 1, 2015 AlignVehicleWithUp function does that for you. Just change g_Vehicle variable. Link to comment
xTravax Posted August 1, 2015 Author Share Posted August 1, 2015 AlignVehicleWithUp function does that for you. Just change g_Vehicle variable. It would work? I don't see where would ':' functions be defined though.. Link to comment
GTX Posted August 1, 2015 Share Posted August 1, 2015 They are in default race utils_client.lua I guess. Link to comment
xTravax Posted August 1, 2015 Author Share Posted August 1, 2015 They are in default race utils_client.lua I guess. Didn't find it there. I thought that this was in oop or something because of ':' stuff. I will keep digging because i'm not using the default race gamemode, and this allign function could help me a lot. Anyway, thanks. If I run into some kind of problem, i'll make a post below. edit: for anyone looking for that Vector3D function location, it's in _commons.lua file in race gamemode. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now