John Smith Posted December 24, 2014 Posted December 24, 2014 hi i need somebody to help me with this how can i calculate the requried velocity x,y,z arguments to throw player away from the colshape in exact opposite direction? like if i was coming from left side to the colshape it would throw me on left side, but behind and not front. please help me if you know how to calculate this direction for setElementVelocity If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
MTA Team botder Posted December 25, 2014 MTA Team Posted December 25, 2014 No compilation errors, but I am not sure if it works. In one sentence: It takes the angle from the player to the colshape, turns it around (negative) and then applies the velocity (before the impact) to push the player away. function handleShapeHit(contactElement, matchingDimension) if not matchingDimension then return end if getElementType(contactElement) ~= "player" then return end local x, y = getElementPosition(source) local px, py, pz = getElementPosition(contactElement) local vx, vy, vz = getElementVelocity(contactElement) local speed = math.sqrt(math.pow(vx, 2) + math.pow(vy, 2) + math.pow(vz, 2)) + 0.25 local angle = -math.atan2(px - x, py - y) setElementVelocity(contactElement, speed * math.cos(angle), speed * math.sin(angle), vz + 0.1) end local col = createColRectangle(-150, -150, 300, 300) addEventHandler("onColShapeHit", col, handleShapeHit) GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
John Smith Posted January 25, 2015 Author Posted January 25, 2015 Your example wasn't working in correct angle anyway i have tried this thing with a marker(it can be done with colshape too if prefered) and it's actually very easy to achieve what i tried to do here's it if anyone needs it local marker = createMarker(0,0,4,"corona",3,255,0,0,255) function ion(hitElement) if source == marker then local x,y,z = getElementVelocity(hitElement) setElementVelocity(hitElement,-x,-y,z+0.5) -- throw element away from marker in opposite direction end end addEventHandler("onMarkerHit",marker,ion) If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
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