Is there a reason why you’re doing all this rather than use actual physics?
I have a sphere in the world. I want the sphere to move at a constant speed. I want the sphere to change direction when it collides.
IF that’s what’s needed, the above seems overengineered. Since you want to take advantage of physics, rely on physics then. Full energy conservation can be achieved by configuring a physical material, overriding restitution and friction. Also, removing mass from a physically simulated body is asking for trouble, imho.
You’d need no script for the above and no special settings apart from removing drag (you’ve done this already) and creating a physical material.
If you absolutely must override physics (which can manifest as a bunch of odd issues further down the line), consider working with direction, not angle:
Alternatively, you could use mirrored velocity from the frame before the hit and skip Direction * Magnitude.
Converting to angles often leads to pigeonholing oneself into a corner, especially in 3D. On top of that, relying on generated physical hits will be awkward, as above. You might be better off using a floating movement component and emulate it instead with movement direction. Setting linear velocity per frame seems wasteful and defeats the purpose using physics in the first place.
Not sure what the real end goal is so I might be off my mark here.
I’m printing velocity every frame in the middle. If the velocity changed due to a massive framerate drop or inadequate float precision (or UE4 + PhysX shenanigans), you could always clamp the vector to ensure it stays as it should and enforce linear velocity then.
I was thinking if i don’t use mass, friction and gravity i would get constant speed because there is not acceleration. But I didn’t know that this would cause problems in the physics simulation. I’m a noob!!
Ok, i won’t use the event OnTick to do this.
At the moment I am shooting projectiles at the sphere. That’s why I don’t want it to stop moving. But I also don’t want it to increase or decrease its speed. Because if it’s too slow it’s boring, and if it’s too fast then it’s very hard to hit. And another problem is when I shoot at it in the same direction of movement, sometimes it speeds up too much and goes through walls.
Ok, Now i seeing variations in the speed of the sphere. Sometimes it goes faster and sometimes it goes slower. I will try it.