- Home /
AddForceAtPosition not working?
What im trying to do is make a fps and make a raycast be the bullet. The problem is when i use addforceatposition it says the point isnt part of unity.transform? Look!
function update() {
if(Input.GetMouseButton(0))
{ var forward = transform.TransformDirection(Vector3.forward);
var hitInfo : RaycastHit;
if (Physics.Raycast (transform.position, forward, hitInfo, 1000)) {hitInfo.rigidbody.AddForceAtPosition (hitInfo.transform.point,forward * 50);
} } }
Can anyone help me with this? Thanks!
I'm wondering if it isn't working right because you have the point and force swapped.
According to the docs, its (force, position), so try this:
hitInfo.rigidbody.AddForceAtPosition(forward * 50, hitInfo.point);
Answer by Statement · Apr 16, 2011 at 08:04 PM
It says the point isnt part of transform
Right you are, a transform doesn't have a point member. It does have a position member, though. Maybe you want to add the force at the hitInfo.point instead?
hitInfo.rigidbody.AddForceAtPosition(hitInfo.point, forward * 50);
Your answer
![](https://koobas.hobune.stream/wayback/20220613123217im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add opposite force of current direction? 2 Answers
Cinimachine virtual camera not updating when in standby mode 1 Answer
3rd pserson shooter camera issue 1 Answer
Why doesn't AddForce work upwards? 0 Answers
Mecanim Fps Shooter? 3 Answers