Question by
ManiaKPT · Apr 16, 2019 at 07:23 PM ·
scripting problemcollisionmovement script
Shopping Cart Movement
Hey guy's,
I'm not very good at programming but i'm trying to make a script which would let the player pick an shopping cart and "drive it" around the scene but it doesn't seem to work quite right, because whenever the shopping cart collides against a wall, it start's sliding away from the player or even starts twitching against the wall which is a problem since the player is only able to stop controlling the cart if he's near it.
I don't know if this script is the best way to control the cart but let me know what you guys think, but the main question would be, is there a way to make the cart not slide away from the player?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Carrinho : MonoBehaviour
{
public GameObject Player;
public GameObject trolley;
private bool isControl;
private void Update()
{
if (Vector3.Distance(transform.position, trolley.transform.position) <= 2f)
{
if (Input.GetKeyDown(KeyCode.E) && !isControl)
{
trolley.transform.SetParent(transform);
trolley.transform.rotation = Player.transform.rotation;
isControl = true;
}
if (Input.GetKeyDown(KeyCode.Q) && isControl == true)
{
trolley.transform.parent = null;
isControl = false;
}
}
}
}
Comment