I want to move a rigid object with following command

So, I want a rigid body to move 24 things on the x axis when i collide with an object but when i run the program i get this error:
Assets/Scripts/PlayerMovement.cs(38,51): error CS0029: Cannot implicitly convert type float' to UnityEngine.Vector3’

This’s my code:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	public float moveSpeed;
	public GameObject deathParticles;

	private float maxSpeed = 5f;
	private Vector3 input;
	private Vector3 spawn;
	public Vector3 location;

	void Start () {
		spawn = transform.position;
		location = transform.position;
	}	

	void Update () {
		input = new Vector3(Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
		if(rigidbody.velocity.magnitude < maxSpeed)
		{
			rigidbody.AddForce(input * moveSpeed);
		}

	}

	void OnCollisionEnter(Collision other)
	{
		if (other.transform.tag == "Enemy") { 		

				Die ();
				
		}
	}

	void OnTriggerEnter(Collider other) {
				if (other.collider.tag == "NextLevel001") {
					transform.position = location.x + 24;
			}
	}

	void Die() 
	{
		Instantiate(deathParticles, transform.position, Quaternion.identity);
		transform.position = spawn;
	}
}

Help would be gladly appreciated :slight_smile:

Just like the error says, you can’t assign a float as a Vector3

transform.position = location.x + 24;

A Vector3 needs 3 values and you are giving it just one… location.x + 24 could be for example 25, and you can’t set an object’s position to be “25”.

Should be

location.x += 24;
transform.position = location;