Gallardo9944 Posted February 11, 2014 Share Posted February 11, 2014 Hello. I'm looking for a way to make an element "boost" into the direction of the camera. Obviously, it has to be done with matrix stuff. I'm not fond of matrix-related stuff, so yeah, I'd like to set element's velocity to +1 into the camera direction point. Any tips or examples? Thanks in advance. Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 You need to use math to get the forward direction of the perspective of the camera, and then set velocity of player that direction using math again in a similar way. Search setting velocity forward, or spawning something infront of a player. Link to comment
Gallardo9944 Posted February 11, 2014 Author Share Posted February 11, 2014 well, getting a vector is not a huge deal, but getting the damn velocity... Here's what I have for now: local vehicle = getPedOccupiedVehicle(localPlayer) local mx,my,mz,mpx,mpy,mpz = getCameraMatrix() local vector = {mx-mpx,my-mpy,mz-mpz} And I'm stuck at this point. Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 I think theres a post with a good example, here : viewtopic.php?f=91&t=46007 Link to comment
Gallardo9944 Posted February 11, 2014 Author Share Posted February 11, 2014 The code is pretty much useless cause it doesn't do what expected. Always throws me in 1 direction. Link to comment
Gallardo9944 Posted February 11, 2014 Author Share Posted February 11, 2014 Okay i found it out myself. Posting the code if someone needs: local vehicle = getPedOccupiedVehicle(localPlayer) local mx,my,mz,mpx,mpy,mpz = getCameraMatrix() local vector = {mx-mpx,my-mpy,mz-mpz} setElementVelocity(vehicle,-vector[1],-vector[2],-vector[3]) It doesn't calculate the difference between velocities, but in fact it does set the direction. Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 Sorry, i didnt check it, i was in class. Link to comment
arezu Posted February 11, 2014 Share Posted February 11, 2014 It doesn't calculate the difference between velocities, but in fact it does set the direction. If you still need to make it only set velocity to 1 in the direction, then divide the components of the vector with the length (normalization) local vehicle = getPedOccupiedVehicle(localPlayer) local mx, my, mz, mpx, mpy, mpz = getCameraMatrix() local dist = getDistanceBetweenPoints3D(mx, my, mz, mpx, mpy, mpz) local vector = { (mx - mpx) / dist, (my - mpy) / dist, (mz - mpz) / dist } setElementVelocity(vehicle, -vector[1], -vector[2], -vector[3]) It may give better result if you use the vehicle position and camera position instead of camera position and camera target position. 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