My question is : Is possible to make “planet” like… sphere, where gravity keeps you on the ground (with possibility to jump of course…) ? Imagine, you are walking to the north till you reach the same point you started from. Is there anyway who would like to help me with that? Thx
I’ve done this in other engines before but never in Unreal. I think the idea is the same.
So, you have this sphere that you want to be treated like a planet. You would need to be able to recognize when an object is within range of this planet and should have gravity applied to it. You can use a SphereComponent
on your mesh to cause a Collision Response of the Overlap
kind. Then you would apply force in the direction of the center of the planet to the object that entered the influence of the planet… and do whatever else you wanted to, like orient the object to the planets position so you could walk on it. [Player down vector = (planetPosition - playerPosition).normalized]
You could implement these objects that are able to have gravity applied like this so that when they Overlap
with a gravity field they get a reference to that planet, get the gravity info from it, and then apply it to themselves. Then when the leave the gravity field, they go back to whatever you want them to do.
For the events to determine if the objects are inside the gravity influence of the planet you can use Begin Overlap
and End Overlap
.
Now this is just the general idea… you can apply it in many ways. If you have a single planet and you simply want to walk and jump around on it, you could simply apply a downward force on your player in the direction of the center of the sphere/planet. This is all that gravity is… a force pushing you down into the floor. If you are using a UCharacterMovementComponent
it would handle all the jumping and movement for you. I believe the jumping is done relative to the orientation of the character, but you would have to look at the code for the UCharacterMovementComponent
to confirm that… otherwise you may have to implement that yourself using forces again.
Hopefully that will get you going in the right direction! =)
Out of the box it is not capable of doing this. On the forums someone had posted a bit of code that accoumplished just this.
That should help you out and get you started. (Requires source engine changes)
I would like a code example or a blueprint function library
Okay, so using trace this looks like it should work however when I enter the gravity volume with the pawn (same thing that the trace originates from) instead of lerping over time to the center of the ball I just teleport to what seems like an arbitrary position and rotation near but outside of the gravity volume, yet each time I reenter at a different point the trace fires and it depicts that it should work… How do I get a gradual translation and rotation(orientation) for my pawn to this ■■■■ ball! ?
Kind regards,
me
Bonus points if this works over a tessellated sphere (hills, mountains, etc)