#Come here
1 messages · Page 1 of 1 (latest)
Youve created a player obkect right
Yeah
Create a script in it
So i did
Ok can you type here the code by
i followed like 3 diffrent "Movement in 10 minutes" videos
`
and cs
Not the whole code then
Just the problem
Although, there is no problem
Lemme explain this thing
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using Unity.VisualScripting;
public class Player : MonoBehaviour
{
private bool JumpKeyWasPressed;
private float HorizantalInput;
private Rigidbody rigidbodyComponent;
[SerializeField] private Transform GroundCheckTransform = null;
[SerializeField] private LayerMask playerMask;
private int SuperJumpsRemaining;
public float playerSpeed;
public float sprintSpeed = 4f;
public float walkSpeed = 2f;
public float mouseSensitivity = 2f;
public float jumpHeight = 3f;
private bool isMoving = false;
private bool isSprinting = false;
private float yRot;
private Animator anim;
private Rigidbody rigidBody;
// Start is called before the first frame update
void Start()
{
rigidbodyComponent = GetComponent<Rigidbody>();
playerSpeed = walkSpeed;
anim = GetComponent<Animator>();
rigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Physics.OverlapSphere(GroundCheckTransform.position, 0.1f, playerMask).Length == 1)
{
return;
}
//Press the space bar to apply no locking to the Cursor
if (Input.GetKey(KeyCode.Space))
Cursor.lockState = CursorLockMode.Locked;
// Check if space key is pressed down
if (Input.GetKeyDown(KeyCode.Space))
{
JumpKeyWasPressed = true;
float jumpPower = 5f;
if (SuperJumpsRemaining > 0)
{
jumpPower *= 2;
SuperJumpsRemaining--;
}
rigidbodyComponent.AddForce(Vector3.up * 5, ForceMode.VelocityChange);
if (!Input.GetKeyDown(KeyCode.Space))
rigidbodyComponent.AddForce(Vector3.zero, ForceMode.VelocityChange);
}
JumpKeyWasPressed = false;
}
There is Input.GetAxis("Horizontal" or "Vertical")
W and s and up and down arrow keys are vertical
A d yata yata
I found a guy on YT that suggested
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam1: MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}```
I think you can define the mouse rotations and stuff inside the Player script
left bottom to top right
And add the Camera's script in your Player script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCamera : MonoBehaviour
{
public Transform cameraPosition;
void Update()
{
transform.position = cameraPosition.position;
}
}
What do you want to do and where we are rn
[SerializeField] infron of transform camPosition
Yesterday I stayed up to 4am trying to fix it without any help and made a mess of maybe 5 diffrent codes and tried to make my own. That didnt really work out so I started over.
At void Start() or Awake()
lemme try
Wait
nope
cameraPosition = GetComponent<Transform>();
Thats how you get the transform component that is inside the object
Im in school rn. I can hrlp 50 minutes later. But others can help too
Its actually pretty simple
worked for 12h
I refused to ask for help
but this shit starts to up my bloodpressure everytime i think i know what todo but actually dont
😄
so when you do public Transform cameraPosition, you define the cameraPosition being in the class of transform
@indigo garden
In Cam script?
Then you'll have to define cameraPosition as the Transform thing in the gameobject
Yeah
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCamera : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
cameraPosition = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
transform.position = cameraPosition.position;
}
}
How the cam scripts looks rn
lemme run it
@vagrant topaz
At Update() youll have to define the cameraPosition.position as...
Actually nothing
Cuz you gonna change it when the player turns
So in player script
At the top
Type
Delete the script
cam script?
You can play with the camera by Player s script
It is its parent object right
The player
That cameraholder is irrelevant right
Yesterday night i had it working but diffrently
I gotchu hollup
In class
Ill dm u in 40min
Im gonna teach it, so everytime you want to do it, you can do it urself
Love