- Home /
how to jump a player where always at the center of game objects
Hi All
I can't figure out how a player jumps always onto the center of a game object like the attached file. what I tried to solve this problem is as below.
player side: I have coded a rigid body to translate 5m/ time.delta time.
ground script is as below. (basically coroutine, 0.5f, the ground will appear and the gap will be 10f(but it is possible to adjust based on the level. ex, the player get further than a certain point, z moving speed is up, so that spawning point of ground will be further.)
my biggest problem is "the player doesn't want to hit the center of the ground sometime, so sometimes, the player position is short from next ground, sometimes it is longer from next ground. it is not consistent. player ground collision point = center of the ground.
is there any way that the player can keep center of a ground object like an attached file?
Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestSpawnManager : MonoBehaviour
{
public GameObject[] load;
public GameObject player;
public Vector3 currentPos;
void Start()
{
Instantiate(load[0], new Vector3(0,0,player.transform.position.x), Quaternion.identity);
StartCoroutine(SpawningLoad());
}
IEnumerator SpawningLoad()
{
while(true)
{
yield return new WaitForSeconds(.5f);
currentPos =transform.position;
transform.position = new Vector3(0, 0, transform.position.z + 10f) ;
Instantiate(load[1], transform.position, Quaternion.identity);
}
}
}
Your answer

Follow this Question
Related Questions
How to spawn cubes on mouse position 1 Answer
UNET: PlayerPrefab's `Start()` is being called before play scene's `Awake()` 0 Answers
Instantiating unique Prefabs to unique child objects in C# 3 Answers
How to respawn player car in war track 1 Answer
Unity creates unreachable navmesh. How can I remove it? 1 Answer