Hello!
So, I have this problem, and I’m checking out different topics but I can’t seem to find the answer. I’m really new to the engine, and I’ve come across something I do not know how to solve. ![]()
I’ve created a cube called Sten, with a script. Within this script I’d like to add force to another object called Potato (without attaching the script to the Potato in the inspector). I’ve managed to rotate it through transform, but I fail to add force to it - even though it has a rigid body in the inspector. If I try to add “public Rigidbody spud”; it already says I’m using that variable - so I’m a bit in the fog right now.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player_movement : MonoBehaviour
{
public Rigidbody physicalmodel;
private float powerforce=100f;
public GameObject spud;
// Start is called before the first frame update
void Start()
{
spud = GameObject.Find("Potato");
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetKey("space"))
{
physicalmodel.AddForce(Vector3.forward * powerforce);
spud.transform.Rotate(0, 100 * Time.deltaTime, 0);
spud.AddForce(Vector3.forward * powerforce);
}
}
}