Skip to content

u/stenkaal

In this archive from Apr 2019 to Aug 2019

2
posts
7
comments
0
media
28
score
1 saved before deletion

Oops wrong code, i hope that was not an effortless question i did not actually see the rules before but here are the codes:

Jump script:

​

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

​

[RequireComponent(typeof(Rigidbody))]

public class Jump : MonoBehaviour {

​

public bool isGrounded;

Rigidbody rb;

void Start()

{

rb = GetComponent<Rigidbody>();

}

​

void OnCollisionEnter(Collision Col)

{

if (Col.gameObject.tag == ("Ground") && isGrounded == false)

{

isGrounded = true;

}

​

​

}

​

​

void Update()

{

if (Input.GetKeyDown(KeyCode.Space) && isGrounded)

{

rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);

isGrounded = false;

}

}

}

​

Movement script:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

​

public class PlayerController : MonoBehaviour {

​

Rigidbody rb;

public float speed = 10.0f;

​

void Start() {

rb = GetComponent<Rigidbody>();

rb.freezeRotation = true;

​

}

​

​

void Update() {

if (Input.GetKey(KeyCode.D))

{

rb.velocity = transform.right * speed;

}

​

if (Input.GetKey(KeyCode.A))

{

rb.velocity = -transform.right * speed;

}

​

if (Input.GetKey(KeyCode.W))

{

rb.velocity = new Vector3(0, 0, 1) * speed;

}

​

if (Input.GetKey(KeyCode.S))

{

rb.velocity = new Vector3(0, 0, -1) * speed;

}

}

}

​

Hope this code helps anything, also if you have any better player controller scripts, if you would like you can comment it because, like i said, any help is apreciated:)

edit: Forgot to mension that i cant jump wile mooving.

1 points

hello im a beginner and i came across this subbreddit. i thought that this will be a good place to start improving my skills. English isint my first language so if my grammar is bad i am sorry. I was wondering if you guys have any tips for me to improve. I will be looking at your entrys to again improve my drawing skills and maybe one day i will post my entry on here aswell and when i do feel free to tell me something i can improve on the drawing! as much as i have seen this subreddit is a kind one. Im looking forward to be a part of this and seeing the amazing artists in the world.😁

13 points

End of this list.

Back to top

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.