kieran Posted February 4, 2018 Share Posted February 4, 2018 I'll be straight up, took the following code straight off another topic from a while back where the guy was getting a ramp to spawn in front of the player, I modified it to move the player, but it moves them forwards and I want to move them backwards.... I am not the best at math but I am trying to learn from scripting, code to move player forwards is below. local x, y, z = getElementPosition ( localPlayer ) local r = getPedRotation ( localPlayer ) x = x + math.sin ( math.rad ( r ) ) * 1.5 --What does this actually do? y = y - math.cos ( math.rad ( r ) ) * 1.5 --And this? setElementPosition ( localPlayer, x, y, z ) setElementRotation ( localPlayer, 0, 0, r ) Can someone explain what's actually happening? It works but my problem is dealing with: math.sin, math.cos and math.rad. Any info would be greatly appreciated. Link to comment
NeXuS™ Posted February 4, 2018 Share Posted February 4, 2018 I'd rather start using OOP, as math.sin and math.cos are taught in school. Link to comment
kieran Posted February 4, 2018 Author Share Posted February 4, 2018 12 minutes ago, NeXuS™ said: I'd rather start using OOP, as math.sin and math.cos are taught in school. I've never touched OOP... What would I need to know for this? Only reason I ask is that I have made a script for a friend where the player climbs up a ladder, that part works fine, but when they go down the ladder (even if I spin them 180 degrees) they glitch through walls and it's horrible. Link to comment
kieran Posted February 4, 2018 Author Share Posted February 4, 2018 3 hours ago, NeXuS™ said: Read this page. Ah thanks, I should of payed attention instead of drawing triangles in class. Link to comment
Moderators IIYAMA Posted February 4, 2018 Moderators Share Posted February 4, 2018 (edited) The value 1.5 represents the offset. Math.sin and math.rad used on the rotation, represents a sort of vector direction of an axis. Which you can multiply by the offset to extend the range. (The original offset is 1 unit.) You should start calculating from the ladder and not from the ped. Else indeed it might causes glitches like that. Edited February 4, 2018 by IIYAMA 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