- Home /
Player Jump in air
Hey guys, I am stuck on a problem. I want that a ghost in my game (with a float script so he flys up and down) jumps but lands again in the air. Does someone out there know how to do that?
Answer by antonsimmerle · Feb 24 at 10:37 AM
Hey, thanks for the answer. My problem is that when the ghost jumps, he lands on the ground, but I want that he lands in the air. Hope you know how I can do that.
I didn't couldn't really understand the question...
It would help if you could send an image of the problem.
I want, that my ghost after he jumps, doesn’t collide to ground, instead lands on a defined position y position in the air
Send me the floating script, i shall(if possible) change it according to your problem...
Here is the Jump script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerJump : MonoBehaviour {
public Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if(Input.GetButtonDown("Jump"))
{
rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
}
}
}
Here is the floating script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FloatGhost : MonoBehaviour {
public Vector3 moveDirection;
public float moveDistance;
public float moveSpeed;
private Vector3 startPosition;
// Start is called before the first frame update
void Start() {
startPosition = gameObject.transform.position;
}
// Update is called once per frame
void Update() {
transform.position=startPosition + moveDirection * (moveDistance*Mathf.Sin(Time.time*moveSpeed));
}
}
Your answer
Follow this Question
Related Questions
ios development question 2 Answers
How do I pause my countdown Timer,when the door will open? 0 Answers
Using multiple materials on a object 2 Answers
Faster movement speed when FPS is lower? 1 Answer
Raycast through object 1 Answer