Im trying to make a Basketball game. Im using the default 3rd Person Map. So far, I added an actor called Basketball, where I added a mesh, material and material effects (bouncy). Then I tried to attach the Basketball to the player (look Bluescrint below). Now Im stuck. I want to release the ball from my player when pressing right-click. In the player blueprint, everything works fine till the Teleport command. The ball is getting in the position, but then it gets stucked in the air, not moving at all, ignoring gravity and physics. Any help/ suggestions why physics are not working on my Basketball?
Where is the My Ball variable being set? What you have to do to toggle physics or collision in real time is: Cast to [Actor] using some reference as input, usually from the level BP, a Get All Actors of Class node, or the resulting Actor output of an overlap > Get Root Component from that cast > Cast to Primitive Component using that Get Root Component. From there you can mess with those properties.
So, in linear fashion: Cast to [Actor] > Get Root Component > Cast to Primitive Component > Set Simulate Physics and/or Enable Gravity.
An alternative is to have a custom event in the actor that toggles physics/gravity on the root component, and you call that event from the Cast to [Actor].
Also, I’ve never used Add Force, but using Add Impulse works. Try that if it just drops to the ground once you get your gravity/physics going.
My Ball is set in player BP (event begin play → raycast on the Basketball which is placed in the game already). But I put all code to level BP now, where I could easily get a reference to the Basketball gameobject. What exactly is the root component, is it the Basketball BP or the Basketball game object? I still dont get why I simple cant disable physics on the ball, then just enable it on a key press event.
I still get the error “BasketballMesh has to have “Simulate Physics” enabled if you’d like to AddImpulse”, even though Im using enable Simulate Physics and set to it to true.
And Im also using the root component, which means I enabled physics on the whole pawn (Mesh+Collision Box).
Tried everything, but whenever I add “set collision”, the ball gets stucked in the hand of the player, even when I teleported the ball somewhere else before. Did I mess something up when I attached the ball to the player?
I feel like I didnt move the root component and only the mesh of the ball, so it stays at the character and when I enable collision, the ball moves and instantly collides with the player, attaching the ball to the player again.
It works now, I have no idea why. Deleted the sphere trigger on the basketball and toggled physics on the mesh component of the basketball. Im still confused why the other blueprint was not working. I post the code below, if you have performance suggestion or something else to add <3
I’m having the same problem:
“… has to have ‘Simulate Physics’ enabled if you’d like to AddImpulse.”
but physics is enabled, 100 sure, it’s enabled both in code and the blueprint, and i can see that it is enabled fro the game…