The game takes place on a large sphere that the player travels around. Something like a Super Stardust HD.
How I can do this with blueprints?
The game takes place on a large sphere that the player travels around. Something like a Super Stardust HD.
How I can do this with blueprints?
Hey, so I made this as an answer:
I apologize if it's long. Basically you need to use the surface normal and the actor forward to create a rotation and keep your character aligned to the surface. (So use Make Rot From ZX). If your input system is different than a twin stick, then you can also combine that Rot with a Rot for the direction you want to face (I don't cover this in the video).Thank you so much!!! Great explanation!
One more question. Can I use this script for projectiles?
Sort of. Depends on what behavior you want for projectiles. If you want them to fall due to the gravity of the planet, you would get the PlanetBP on begin play the same way I did for the Pawn, and then on every tick of the Projectile you would want to add -980 * SurfaceNormal (from PlanetBP) to the velocity on the ProjectileMovement. If you want the Projectile to stay the same distance from the surface of the planet, and curve around it, that’s a little more difficult to do. The simplest way I suppose is to get the distance from the surface and basically do the same thing you do with the ship, but set it to a position a position with the offset of the initial distance from the surface.
Thanks! I give it a shot)
The simplest way I suppose is to get the distance from the surface and basically do the same thing you do with the ship, but set it to a position a position with the offset of the initial distance from the surface.
i need to do this in projectile BP or in firing function?
Okay so this is a harder problem than I initially led on. You also have to rotate your velocity.
Anyway, to answer your question, you should store the distance of your projectile from the center of the planet after you get the planet on the projectiles on begin play. Then on every tick you need to get the surface normal and then multiply that normal by the distance you stored. That will give you the new location you should set your projectile to. However, as I mentioned, you’ll also have to rotate the velocity, which you’ll see why once you get this positioning part done
So, I tried, but not result. Projectiles spawn in the right places, but dont moving. What I do wrong?
You are currently setting the velocity in local space, and it should be in world space. What ways have you tested this? Firstly, we should determine: What’s the behavior if you remove the velocity rotation code? I’m guessing it will curve with the planet but slow down as it does so until it basically stops moving horizontally from where you shot. One thing you can do also is put a Arrow component on the projectile, scale it up, and then make it NOT hidden in game so you can see if its properly rotating around the planet.
Now that we know that part is working, we go back to velocity. You are over-rotating the velocity. What I mean is, Imagine your current velocity has some rotation in world space, you are attempting to give it a new rotation. But what you’re actually doing is applying that new rotation on top of the old rotation, and as a result the velocity might just be spinning in place because on every update the projectile will be over-rotated. So to fix that, we need to RotateVector based on the previous rotation. We subtract the new rotation from the current rotation, and then Rotate Vector by that rotation (since it should basically rotate from the current to the new).
I think the easiest thing to do is to subtract that new rotation from the GetActorRotation BEFORE you do Set Actor Locatioin and Rotation (so just set velocity before rather than after). The difference of those 2 rotations is what you’ll rotate your velocity vector by.
I just noticed. You are calculating the distance to the planet on every tick. This is not storing that result! You should make a float variable on projectile that you set with Get Distance To. Otherwise, what you have will ask for the distance to the planet on every tick, which is inefficient and might cause issues with our approach.
You forgot to set the Velocity before Set Actor Location and Rotation. You are getting a Delta Rotator of 0 because of this (since you are getting the Actor Rotation and subtracting it from the rotation you just set the Actor to).
EDIT:
Also, the new location needs to be the (SurfaceNormal*DistanceToCenter) + Planet.GetActorLocation() for the cases where your planet is not centered at 0,0,0.
EDIT 2:
Next I disabled Rotation Follows Velocity on the movement component since we’re manually controlling rotation here. I don’t have this working just yet, but I think we’re close.
Okay so the rotations are still weird, so I changed the logic to something simpler. Basically I just set the Velocity to the initial velocity vector rotated. This is pretty much a hack.
It works!!! Finally))) Thank you for great help!!
any chance you know how to do this with keyboard and mouse?
HI Cobryis,Copperm1ne, I know its been some years since these posts but i’ve been reading your post of trying to fire a projectile around a sphere planet like Super Stardust HD. How did you finally get it to work? Would greatly appreciate your insight
Hi all, It didn’t exist back in 2015 when this thread was made, but I just wanted to post this recent tutorial incase this thread is appearing in google searches etc