Hello everyone. I’m a brand new coder and I’m taking courses to try and get up to speed. However, I’m having an issue where I have a player object that has prefab set coordinates. When I press play to test my game, the player object is put in the middle of the plane and halfway down into the plane so that it can’t move. I’m not sure how to resolve the issue so I figured I would put the scripting I have for it here in hopes that someone can find the issue that I’m not familiar with spotting just yet.
Note: The code itself isn’t complete. I’ve just made it to take care of horizontal movement and haven’t given it a full jump script yet. Mostly because it’s pointless till I can get it out of the ground. >.>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BuddyController : MonoBehaviour{
//walking speed
public float walkSpeed;
//jumping speed
public float jumpSpeed;
//Rigidbody Component
Rigidbody rb;
// Use this for initialization
private void Start(){
// Grab component
rb = GetComponent();
}
// Update is called once per frame
private void FixedUpdate () {
WalkHandler();
JumpHandler();
}
// Takes care of walking logic
void WalkHandler()
{
// Input on X (horizontal)
float hAxis = Input.GetAxis(“Horizontal”);
float vAxis = Input.GetAxis(“Vertical”);
// Movement Vector
Vector3 movement = new Vector3(hAxis * walkSpeed * Time.deltaTime, 0, vAxis * walkSpeed * Time.deltaTime);
// Calculate new position
Vector3 newPos = transform.position = movement;
// Move
rb.MovePosition(newPos);
}
// Takes care of jumping
void JumpHandler()
{
}
}