- Home /
move Object without coroutine
I make a FPS Zombie Game and I have a problem with the bullets.
The bullet is simulated with raycast. The object I look is moved forward and you see a shoot hole. I use for the movement Rigidbody.MovePosition and for the hole http://u3d.as/content/edelweiss-interactive/decal-system/36o.
But when I use that the movement look like a teleportation.
So I want that the object I shoot move smooth forward but without any routine and coroutine. Like a nudge. With physics and all. And the solution with a physically bullet has make in my project some problems, so is this no alternativ.
And when someone need it, hier is my script for the object who shoot:
#pragma strict
var bullet : Transform;
var ent : float;
private var stat : float;
function Update () {
if (Input.GetButtonDown ("Fire1")) {
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit)) {
if(hit.rigidbody != null) { //hit.transform.lossyScale +2
var pos : Vector3 = Camera.main.transform.forward * ent + hit.rigidbody.position;
var hit2 : RaycastHit;
// Debug.Log(pos);
for(var i :int = 0; i<6; i++) {
var a : Vector3;
var b : int;
a[i/2] = 2;
if( i % 2 != 0)
a[i/2] = -2;
//Debug.Log(i);
b = hit.transform.lossyScale[i/2];
if(Physics.Raycast(hit.rigidbody.worldCenterOfMass, a, hit2)) {
if(hit2.distance < (b+0.4)/2)
pos[i/2] = hit.rigidbody.position[i/2];
}
a[i/2] = 0;
//Debug.Log(i/2);
}
Debug.Log(pos);
hit.transform.position = pos;
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613135726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shooting with the maneuvering of the ship 0 Answers
A Bullet's rigidbody, hit.normal 4 Answers
Bullet Launcher Script 1 Answer
Best way to shoot physical bullets? 2 Answers