I am new to programming on c#, I have been watching a 3 and a half hour tutorial and up to this point everything was going smooth. The error message says "There is no argument given that corresponds to the required formal parameter 'force' of 'ForceReceiver.AddForce(Vector3, float)' ". I am aware that it is a common problem but the other answers online have not helped me. I do not understand what has happened incorrectly with the script, here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ForceReceiver : MonoBehaviour{
public float deceleration = 5;
public float mass = 3;
private Vector3 intensity;
private CharacterController character;
void Start()
{
intensity = Vector3.zero;
character = GetComponent<charactercontroller> ();
}
void Update()
{
if (intensity.magnitude > 0.2f) {
character.Move (intensity * Time.deltaTime);
}
intensity = Vector3.Lerp (intensity, Vector3.zero, deceleration * Time.deltaTime);
}
public void AddForce (Vector3 direction, float force ) {
intensity += direction.normalized * force / mass;
}
}
This code is for a knockback affect for damage in my game which is connected to this player script...
} else if (otherCollider.GetComponent<bullet>() != null) {
Bullet bullet = otherCollider.GetComponent<bullet> ();
if (bullet.ShotByPlayer == false) {
hazard = bullet.gameObject;
health -= bullet.damage;
}
}
if (hazard != null) {
isHurt = true;
Vector3 hurtDirection = (transform.position - hazard.transform.position).normalized;
Vector3 knockbackDirection = (hurtDirection = Vector3.up).normalized;
GetComponent<forcereceiver>().AddForce (knockbackDirection * knockbackForce);
StartCoroutine (HurtRoutine ());
}
The Unity error message says its on this line
GetComponent<forcereceiver>().AddForce (knockbackDirection * knockbackForce);
I am completely clueless on what the problem is. If you know, your help would be much appreciated. If you need any more of my scripts or examples to find out what the problem is just tell me. Thank you.
What I have tried:
I looked every where for the answer, but being new to programming I am not sure what the problem is. I made sure my code was the same as the tutorial numerous times, and on the same version of unity.