- Home /
Stop the player at center of cube mesh
Hello! I need to stop the player exactly in the center of the cube (the upper side) Tell me how is it better do it? the blue dot is the stopping place. Thx!
Player movement code is simple
transform.position += transform.forward * Time.deltaTime * movementSpeed;
Answer by hawksandwichgames · Jun 01, 2018 at 08:22 AM
Here's a way of doing it. It's the simplest I can think of, but it's not the least performance costly so it might be worth optimizing.
public Transform blueDotStoppingPoint;
void FixedUpdate () {
if (Vector3.Distance(transform.position, blueDotStoppingPoint.position) > 0.1f) {
transform.position += transform.forward * Time.deltaTime * movementSpeed;
}
}
Don't work ( I already tried it. The player goes ahead. But thanks for attention to my question
That'll definitely work, he must not be co$$anonymous$$g within 0.1m of the blue dot. Try increasing the number until it works. Also are the origins of both the player and the blue dot in the right spots for it to work?
Answer by Unified2000 · Jun 01, 2018 at 11:44 AM
transform.position=Vector3.Lerp(transform.position,blueDotPosition+playerHeight/2,movementSpeed);
Your answer
Follow this Question
Related Questions
How could i make my character invisable - but allow my player to still be damaged 2 Answers
Changing Mesh and Mesh Collider of an Object 0 Answers
Determine if two meshes overlap, without using bounds or trigger? 0 Answers
A few questions about the Navigation Mesh stuff 0 Answers
Set the position of a softbody? 0 Answers