Question by
Sanivel · Jan 11, 2021 at 02:13 PM ·
velocityaddforcetransform.position
Change transform.position into addForce or velocity
Hi, I'm new to Unity.
I'm trying to make a VR maze with terrain stamp map but the character(camera) is passing through the wall. So I tried to search the solution and I finally realised that using transform.position code is not appropriate for this.
Here's the code.
public class PlayerWalk : MonoBehaviour { public int playerSpeed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Fire1"))
{
transform.position = transform.position + Camera.main.transform.forward * playerSpeed * Time.deltaTime;
}
}
}
How can I change this transform code into addforce or velocity code, please?
Thanks.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613023024im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to add force to an object... is this done correctly? 0 Answers
Unity3D - Making an object follow the other with the same velocity (variable speed) 1 Answer
how get velocity from swipe fast or slow speed 1 Answer
How to set rigidbody velocity and angularVelocity to Vector3.zero over time? 1 Answer