Jump to content

How to implement weapon accuracy?


splash27
 Share

Recommended Posts

In a shooter game I can calculate the vector with direction that player look at. This vector can be used to guide the bullet. But in this case the weapon will have 100% accuracy. I want to add a random angle (within limited range) to this vector to simulate accuracy less than 100%. So, the question is how to get rotated vector in 3D space?

Link to comment
Share on other sites

 

hi use MAth : (Math.random()*1.-0.5)*0.1

https://www.babylonjs-playground.com/#2GXKNW#32

    var pos = camera.position;

    var tar = {
       x:camera.getTarget().x*1.+(Math.random()*1.-0.5)*0.1-pos.x,
       y:camera.getTarget().y*1.+(Math.random()*1.-0.5)*0.1-pos.y,
       z:camera.getTarget().z*1.-pos.z};

    var r = new BABYLON.Ray( pos,tar,1000.);

    var meshFound = scene.pickWithRay(r );

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...