I’m basically trying to achieve a somewhat dynamic “moon” kind of system, when I get close to one of my planets I would like the player to get stuck in its orbit so it will rotate and follow the planet.
If I’m right, I think sure it’ll be something to do with the player’s relative location and rotation relative to the planet but I can’t figure out the logic after that.
You’d definitely wanna start with an invisible sphere component in your planet BP. Add events for the sphere component for begin and end overlap. This will be your little event horizon for the planet’s influence.
There’s a way few ways to handle to orbit. If you’re wanting it to be according to the planet’s axis/magnetic field, you could simply add relative rotation to the sphere component with a looping timeline on Begin Play that has a float going from 0-360 and plug it into the relative rotation’s yaw. You should be able to rotate the original component itself to whatever tilt you need and the relative rotation will take care of the spinning along that “axis”.
Then, on begin overlap of that component, use Attach Actor to Component, using the sphere component is In Parent and the actor from the overlap as Target. Fiddle around with the attach options, like Snap to Target, etc., to get the behavior you want (I believe Snap to Target is what you want though).
On end overlap of the sphere component, you’d use a simple detach actor from actor node to end the effect.
It’s when you get in the realm of wanting the player to be able to move around the planet according to its own gravity that things get complicated. That involves disabling gravity in the character and using Force to create artificial gravity based on the vector direction of your character and the planet’s center, and also updating the character’s relative rotation to keep it aligned with what’s happening.
Does that give you some ideas to start experimenting? Let me know!
Yeah that is exactly along the lines of what I was thinking I needed to do, I was just unsure of how to implement it. I have it mostly set up now, but when I overlap the sphere component the planet just jumps to another position, I’m guessing it’s something to do with the relative rotation.
Play around with the Attach Location Type. And I wouldn’t do Weld Simulated Bodies. It probably wouldn’t affect this it’s probably bad practice for this kind of situation, where you wouldn’t their two collisions to be considered one.
You should also play around with a Timeline for the rotation. Timelines are powerful tools for BP scripting. You can create graphs within them that output values overtime, set their length, play/stop/reverse them, and even loop them so they continue until they’re stopped.
I was just testing and figured out what was happening (I still don’t know how to fix it though). I switched the In Parent and Target and noticed that the planet then jumps to directly underneath me. It doesn’t seem to be keeping the relative position. Even when changing the Attach Location Type it still doesn’t have the desired effect.