Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 6 7 8 9 10 … 18 Next »
Rotating an entity with a center of rotation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Mode
Rotating an entity with a center of rotation
04-08-2017, 04:01 AM,
#3
Kosmos Offline
GMod Admin
Posts: 180
Threads: 3
Joined: Dec 2013
RE: Rotating an entity with a center of rotation
I think the best way to do this is with localToWorld and worldToLocal (which are global functions, not only entity methods).
Here's an example function which does this:
Code:
function rotateAroundPoint(entity, worldPos, rotAngle) local rPos, rAng = worldToLocal(entity:pos(), entity:ang(), worldPos, Angle()) rPos, rAng = localToWorld(rPos, rAng, worldPos, rotAngle) entity:setPos(rPos) entity:setAng(rAng) end
Explanation of what the code does:
First it calculates which relative position and angle the entity currently has. Then it implicitly (because this merely follows from not using the same local coordinate system when translating from and to world) rotates the position and angle. Finally those values are converted to world again and applied to the entity. Note that this code does basically what Veegi said but without needing a parent entity. This also means you have to do it frequently, so if you want some rotating ring, use a Hologram and it's setAngVel method - that's a very useful thing those holos have.
Find
Reply
« Next Oldest | Next Newest »


Messages In This Thread
Rotating an entity with a center of rotation - by Salira - 03-08-2017, 06:59 PM
RE: Rotating an entity with a center of rotation - by Veegi - 03-08-2017, 09:24 PM
RE: Rotating an entity with a center of rotation - by Kosmos - 04-08-2017, 04:01 AM
RE: Rotating an entity with a center of rotation - by Salira - 06-08-2017, 10:22 PM

  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.