Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Help With 3d Puzzle Game Riddle

Discussion in 'Scripting' started by thrillvillefan98, Apr 11, 2019.

  1. thrillvillefan98

    thrillvillefan98

    Joined:
    Apr 11, 2019
    Posts:
    4
    Greetings, Unity Community.

    I'm trying to make a puzzle game involving picking up portraits and placing them in an order that corresponds to a riddle. I found a script that allows me to place them, but I haven't gotten any luck trying to find one that could let me place them on a wall. I'm trying to make the puzzle spawn a treasure chest if it was solved correctly, but I haven't gotten any luck finding a script that enables that, too. Basically, this game consists of placing portraits on the wall that correspond to a riddle next to it. And if it's solved correctly, you get to obtain an item and continue with the game. Can someone help me solve this problem? It's for a university assignment. Any form of help is appreciated.

    Best Regards,

    - Christian
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    2,205
    That's a lot of complex problems to solve in a single forum post. Like everything with programming, break the problem down into steps to start small and build it up from there.

    Are you able to pick up and place the objects? What does your script look like?
     
  3. thrillvillefan98

    thrillvillefan98

    Joined:
    Apr 11, 2019
    Posts:
    4
    I am able to pick up and place the objects, but I can only drop them once I release a specific button.

    This is the code I used to make it able to pick up items. For some reason, the FPS Controller is now moving left and right and can't look up and down anymore after I implemented this script to the objects; especially after assigning a parent and a rigid body to them:

     using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PickUp : MonoBehaviour
    {
    readonly float PlaceItem;
    Vector3 objectPos;
    readonly float distance;

    public bool canHold = true;
    public GameObject item;
    public GameObject tempParent;
    public bool isHolding = false;

    // Update is called once per frame
    void Update()
    {
    //Check if holding
    if(isHolding==true)
    {
    item.GetComponent<Rigidbody>().velocity = Vector3.zero;
    item.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
    item.transform.SetParent(tempParent.transform);

    if(Input.GetMouseButtonDown(1))
    {
    //pickup
    }
    }
    else
    {
    objectPos = item.transform.position;
    item.transform.SetParent(null);
    item.GetComponent<Rigidbody>().useGravity = true;
    item.transform.position = objectPos;
    }
    }

    private void OnMouseDown()
    {
    isHolding = true;
    item.GetComponent<Rigidbody>().useGravity = false;
    item.GetComponent<Rigidbody>().detectCollisions = true;
    }

    private void OnMouseUp()
    {
    isHolding = false;
    }

    }

     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    2,205
    Maybe the item's rigidbody not being set to kinematic after being picked up is interfering with your character.
     
  5. thrillvillefan98

    thrillvillefan98

    Joined:
    Apr 11, 2019
    Posts:
    4
    It's alright. My teacher helped me with the project, with the additional replies mentioned, so it's all set. Thank you.
     
    GroZZleR likes this.