Answer the question
In order to leave comments, you need to log in
Need help with modifying the control script, who can tell?
Good day everyone needs help in this matter, there is a code taken also on the habrahabr resource. The code is written for unity3d, so the character control code is written there. the problem with the jump, I don’t know how to fix it so that the jump would be possible only from the ground of another collider, the code itself, here’s the
code is not mine:
using UnityEngine;
using System.Collections;
public class CharController : MonoBehaviour
{
public Rigidbody2D rb2d;
public float playerSpeed;
public float jumpPower;
public int directionInput;
public bool groundCheck;
public bool facingRight = true;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
void Update()
{
if ((directionInput < 0) && (facingRight))
{
Flip();
}
if ((directionInput > 0) && (!facingRight))
{
Flip();
}
groundCheck = true;
}
void FixedUpdate()
{
rb2d.velocity = new Vector2(playerSpeed * directionInput, rb2d.velocity.y);
}
public void Move(int InputAxis)
{
directionInput = InputAxis;
}
public void Jump(bool isJump)
{
isJump = groundCheck;
if (groundCheck)
{
rb2d.velocity = new Vector2(rb2d.velocity.x, jumpPower);
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Answer the question
In order to leave comments, you need to log in
In Update()
groundCheck = Physics.Raycast(...);
https://docs.unity3d.com/ScriptReference/Physics.R...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question