Looking to setup add force to an object based on its collision point with another object. Essentially a bumper in a pinball game, apply a force based on the normal of the collision between the ball and the bumper, tried a few things but fumbling with getting it all hooked up properly. I am unable to choose my ball rigid body in any lists.
Is that the only issue? You probably mixed up Rigidbody and Rigidbody2D (completely different systems) or else you have a compiler error you aren’t noticing that you need to fix.
To check your errors, make sure your log console selector buttons are enabled. See this graphic:
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
- the description of the error itself (google this; you are NEVER the first one!)
- the file it occurred in (critical!)
- the line number and character position (the two numbers in parentheses)
- also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
Thanks for the reply, no its the rigid body, no errors but the ball rolls and bounces and collides with the bumper and triggers the force just fine, but it doesn’t effect the ball.
I guess the real issue is that I cannot add the force to the ball, I have tried a bunch different setups.
using UnityEngine;
public class Bumper : MonoBehaviour
{
void OnCollisionEnter(Collision c)
{
c.rigidbody.AddForce(c.GetContact(0).normal*3,ForceMode.Impulse);
}
}
Thank you, I really would like to do this with visual scripting. I appreciate the reply and will go this way if I need to.
Apologies, didn’t notice the visual scripting tag (new forum layout).
I haven’t done much Visual Scripting, don’t have much to offer on it, but all the same caveats about Physics still apply: you must move things only through the physics API, and also the fact that there are two different physics systems in play and to make sure you’re on the right one.
It may be useful to you to make a fresh scene and script graph and get basic collisions working rather than trying to do it concurrently in your actual game setup. This is just basic isolation engineering: prove it works in isolation before trying to integrate.
I actually got it figured out, it was a silly mistake with the physics overlap sphere. I am was trying to do too much. Thanks for your time.